在GridView的EditTemplates中使用DropDownList [英] Using DropDownList in EditTemplates of a GridView
问题描述
alt text http:// www.freeimagehosting.net/uploads/e45e5b66d4.jpg
当用户单击以编辑行时,我使用编辑模板显示域在DropDownList中。但是问题是,当DropDownlist加载数据时,它会丢失'Domain'的当前值。
ie 如果我要编辑第4行,它的域是当前设置为计算机正在更改为MBA,这是DataSource返回的第一个元素。
alt text http://www.freeimagehosting.net/uploads/7d3f6ba9a5.jpg
我想在DropDownList中显示当前值('computers')作为选定值。但是我无法获得正在编辑的域的值。
解决异常使用AppendDataBoundItems =true 。
< asp:DropDownList ID =ddlCategoryrunat =serverSelectedValue ='<%#Eval域)%>'
DataSourceID =datasource
DataTextField =textDataValueField =valueAppendDataBoundItems =true>
< asp:ListItem Text =Select ...Value =>< / asp:ListItem>
< / asp:DropDownList>
I am working on a GridView in Asp.Net. When initially a the Page Loads, my gridview look like: alt text http://www.freeimagehosting.net/uploads/e45e5b66d4.jpg
When a user clicks, to edit a row, I am using edit templates to show 'Domain' in a DropDownList. But problem is , when the DropDownlist gets load with data, it lost the current value of the 'Domain'.
i.e If I want to edit 4th Row, its domain which is currently set to 'Computers' is getting changed to 'MBA' which is ofcourse the first element return by the DataSource.
alt text http://www.freeimagehosting.net/uploads/7d3f6ba9a5.jpg
I want to display the current value ('computers') as the selected value in DropDownList. But I am unable to get the value of Domain, which is being edited.
to solve exception use 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>
这篇关于在GridView的EditTemplates中使用DropDownList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!