Monday, May 16, 2011

Setting gridview edititemtemplate dropdownlist selectedvalue

This is a very quick way of setting the selectedvalue of dropdownlist in gridview edittemplate...

Just add the following to your dropdownlist

SelectedValue='<%# Bind("acceptance") %>' AppendDataBoundItems="true"


The entire column would look something like this




<asp:TemplateField HeaderText="Acceptance">

                <ItemTemplate>

                    <asp:Label ID="Acceptance" runat="Server" Text='<%# calcAcceptance((int) Eval("acceptance")) %>'  />

                </ItemTemplate>

                <EditItemTemplate>

                <asp:DropDownList ID="ddlAcceptance" runat="server"  SelectedValue='<%# Bind("acceptance") %>' AppendDataBoundItems="true">

                    <asp:ListItem Value="0">Acceptable</asp:ListItem> 

                    <asp:ListItem Value="1">Required</asp:ListItem> 

                </asp:DropDownList>

                </EditItemTemplate>

            </asp:TemplateField>




1 comment:

Unknown said...

i try ur code but it not working in GridView1_RowEditing
event Please help me