我正在 Asp.Net 中处理 GridView。当最初页面加载时,我的 gridview 看起来像: alt text http://www.freeimagehosting.net/uploads/e45e5b66d4.jpg
当用户单击以编辑行时,我使用编辑模板在 DropDownList 中显示“域”。但问题是,当 DropDownlist 加载数据时,它丢失了“域”的当前值。
即 如果我想编辑第 4 行,其当前设置为 'Computers' 的域正在更改为 'MBA' 这当然是DataSource 返回的第一个元素。 alt text http://www.freeimagehosting.net/uploads/7d3f6ba9a5.jpg
我想将当前值(“计算机”)显示为 DropDownList 中的选定值。但是我无法获取正在编辑的域的值。
请您参考如下方法:
要解决异常,请使用 AppendDataBoundItems="true"。
<asp:DropDownList ID="ddlCategory" runat="server" SelectedValue='<%# Eval("Domain") %>'
DataSourceID="datasource"
DataTextField="text" DataValueField="value" AppendDataBoundItems="true">
<asp:ListItem Text="Select..." Value=""></asp:ListItem>
</asp:DropDownList>
