1

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.

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.