Help referencing ddl in ItemTemplate vs EditItemTemplate

  • Thread starter Thread starter VB Programmer
  • Start date Start date
V

VB Programmer

I have a datagrid with a dropdownlist in it. As I understand it, the
ItemTemplate section represents the cell when not in edit mode and the
EditItemTemplate section represents the cell when in edit mode. For
simplicity let's call ddl in ItemTemplate section "ddl1" and the ddl in the
EditItemTemplate section "ddl2".

I am trying to set the SelectedIndex value for the ddl's. When not in edit
mode I can set set an object to ddl1 with no problem. Here's how I do it:

MyDdlObject = CType(e.Item.Cells(1).FindControl("ddl1"), DropDownList)

When I try it with ddl2 I get Nothing.

MyDdlObject = CType(e.Item.Cells(1).FindControl("ddl2"), DropDownList)

How can I access this ddl that is in the EditItemTemplate section?

Thanks!
 
VB said:
I have a datagrid with a dropdownlist in it. As I understand it, the
ItemTemplate section represents the cell when not in edit mode and the
EditItemTemplate section represents the cell when in edit mode. For
simplicity let's call ddl in ItemTemplate section "ddl1" and the ddl in the
EditItemTemplate section "ddl2".

I am trying to set the SelectedIndex value for the ddl's. When not in edit
mode I can set set an object to ddl1 with no problem. Here's how I do it:

MyDdlObject = CType(e.Item.Cells(1).FindControl("ddl1"), DropDownList)

When I try it with ddl2 I get Nothing.

MyDdlObject = CType(e.Item.Cells(1).FindControl("ddl2"), DropDownList)

How can I access this ddl that is in the EditItemTemplate section?

Are you trying to do this while not in edit mode? If so, you can't,
since the edititem does not exist; the regular itemtemplate is the type
of item being used. If you were in edit mode, the second one looks like
it should work.

May I ask why you have a dropdown in regular (itemtemplate) and
edittemplate both? Normally you show a label in the itemtemplate, then
when the user wants to edit, you have your edititemtemplate with the
dropdown. If you really do need this, you'll need to bind one of the
dropdowns (whichever one applies) everytime the user switches between modes.
 
Thanks for the response Craig. I will double check the 'edit mode' thing.

FYI: I have a disabled ddl in itemtemplate, so people know that in edit mode
it is a ddl. Just GUI preference. :)

How can I tell the current 'mode' I'm in? How can I set the current 'mode'?

Thanks!
 
Back
Top