Set value in gridview for dropdownlist template. Asp.Net
I have problem with DropDownList template in Grid View, after I go in edit mode drop down have to be selected by current item instead of default value.
<asp:TemplateField HeaderText="Tour Type">
<EditItemTemplate>
<asp:DropDownList AppendDataBoundItems="true" DataSourceID="dropDownListSqlDataSource" runat="server" DataValueField="idTypetour" DataTextField="title"></asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<%#Eval("typeTitle")%>
</ItemTemplate>
</asp:TemplateField>
I tried to use Selecte开发者_运维知识库dValue="<%#Eval("typeTitle")%>", but has no results.
Try to use Bind
instead of Eval
:
SelectedValue='<%# Bind("idTypetour") %>'
The DataValueField is "idTypetour" and the DataTextField is "title", you have tried to use Eval("typeTitle"). What column is typeTitle
? I assume that this must be idTypetour
because you want to set the SelectedValue, what normally is the ID.
Here are informatons on the differences: http://msdn.microsoft.com/en-us/library/ms178366.aspx
精彩评论