Yara
Yara

Reputation: 4565

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 SelectedValue="<%#Eval("typeTitle")%>", but has no results.

Upvotes: 1

Views: 3061

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460168

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

Upvotes: 3

Related Questions