Dropdownlist disappear when put it in EditItemTemplate

340 Views Asked by At

If I put my dropdownlist column in ItemTemplate, it appear but I can't change the value. When I put it in EditItemTemplate like this:

<EditItemTemplate>
     <asp:DropDownList DataValueField="COLUMN_NAME" DataTextField="COLUMN_NAME" DataSource='<%#GetDataSourceDesCol()%>' Width="90%" Visible=true ID="ddlDesCol" runat="server">
     </asp:DropDownList>
</EditItemTemplate>

Then my ddl is not showing any more. How to fix it?

p/s: Even that I try with a new project and simple code like:

<asp:GridView ID="GridView1" AutoGenerateColumns=false runat="server">
     <Columns>
          <asp:TemplateField>
               <EditItemTemplate>
                     <asp:DropDownList ID="DropDownList1" runat="server">
                     </asp:DropDownList>
               </EditItemTemplate>
          </asp:TemplateField>
      </Columns>
</asp:GridView>

The ddl is not showing too!

1

There are 1 best solutions below

0
On

All the controls inside the edit item template will be visible only when the grid view is in the edit mode.

So, you need to set the grid to edit mode. Inorder to make your code to work.

Hope this helps..

if you want to put entire grid view in edit mode:

protected void btnEdit_Click(object sender, EventArgs e)
    {
        GridView1.EditIndex = 1;
    }

if you want a particular row to be in edit mode

Just implement the Row_Editing event and do something like this:

protected void Row_Editing(object sender, GridViewEditArgs e) 
{
  myGridView.EditItemIndex = e.EditItemIndex; 
  BindData(); 
}

Bind data will populate the GridView with the data.