G
Guest
Hi,
I'm building a maintenance form for a table and some of the fields are
textboxes (i.e name) and some should be dropdowns (i.e country of origin)
When a user clicks 'Edit' in the <asp:EditCommandColumn> I want either a
textbox or dropdown to appear when I check what is being edited.
I thought I could create the dropdown on the fly and add it to the datagrid
as below but It's not appearing. I imagined I could populate the dropdown
with codes at this point too.
private void dgCompany_Edit(Object sender, DataGridCommandEventArgs e)
{
dgCompany.EditItemIndex = e.Item.ItemIndex;
DropDownList ddwn = new DropDownList();
ddwn.ID = "dynamicDdwn";
e.Item.Cells[0].Controls.Add(ddwn);
}
Is this approach valid? I thought of maybe creating BOTH the textbox and the
dropdown at design time and hide or show the control in the Edit event using
((TextBox) e.Item.FindControl("txtValue")).Visible = false;
or
((DropDownList) e.Item.FindControl("listValue")).Visible = false;
but I got 'object not set to instance of object'
I'm building a maintenance form for a table and some of the fields are
textboxes (i.e name) and some should be dropdowns (i.e country of origin)
When a user clicks 'Edit' in the <asp:EditCommandColumn> I want either a
textbox or dropdown to appear when I check what is being edited.
I thought I could create the dropdown on the fly and add it to the datagrid
as below but It's not appearing. I imagined I could populate the dropdown
with codes at this point too.
private void dgCompany_Edit(Object sender, DataGridCommandEventArgs e)
{
dgCompany.EditItemIndex = e.Item.ItemIndex;
DropDownList ddwn = new DropDownList();
ddwn.ID = "dynamicDdwn";
e.Item.Cells[0].Controls.Add(ddwn);
}
Is this approach valid? I thought of maybe creating BOTH the textbox and the
dropdown at design time and hide or show the control in the Edit event using
((TextBox) e.Item.FindControl("txtValue")).Visible = false;
or
((DropDownList) e.Item.FindControl("listValue")).Visible = false;
but I got 'object not set to instance of object'