Tsukasa
Tsukasa

Reputation: 6552

ASP.NET GridView DropDownList in Edit assign what is selected

 <asp:TemplateField HeaderText="Upgrade" SortExpression="Upgrade">
            <ItemTemplate>
                <asp:Label ID="LabelUpgrade" runat="server" Text='<%# Eval("Upgrade") %>' />
            </ItemTemplate>
            <EditItemTemplate>
                <asp:DropDownList ID="ddlUpgrade" runat="server" Width="100px">
                    <asp:ListItem Value="1">--Select--</asp:ListItem>
                    <asp:ListItem Value="2">1</asp:ListItem>
                    <asp:ListItem Value="3">2</asp:ListItem>
                    <asp:ListItem Value="4">3</asp:ListItem>
                    <asp:ListItem Value="5">4</asp:ListItem>
                    <asp:ListItem Value="6">5</asp:ListItem>
                </asp:DropDownList>
            </EditItemTemplate>
        </asp:TemplateField>

When I click edit on the GridView I need to take the value of the LabelUpgrade and assign it to the selected item in the DropDownList

Upvotes: 0

Views: 2710

Answers (1)

Richard Deeming
Richard Deeming

Reputation: 31198

Try:

<asp:DropDownList ... SelectedValue='<%# Bind("Upgrade") %>'>

Upvotes: 1

Related Questions