DropdownList in EditTemplate

  • Thread starter Thread starter Yan Wang
  • Start date Start date
Y

Yan Wang

I can populate the dropdown box in a edittemplate correctly. I can even
have the dropdown preselect the correct value returned from my
database. However, I cannot capture the selected value when I edit the
column. It always updated the column to the first item in the list
regardless of
what I select when it is in edit mode. Anyone has the same problem?

Thanks a lot!
 
Yan said:
I can populate the dropdown box in a edittemplate correctly. I can
even have the dropdown preselect the correct value returned from my
database. However, I cannot capture the selected value when I edit the
column. It always updated the column to the first item in the list
regardless of
what I select when it is in edit mode. Anyone has the same problem?

Thanks a lot!

On postback, make sure the datagrid or datalist is re-created in the
same way, with the same dropdown lists present (a control can
not restore its state when it's not there anymore).
This means that you need to databind the grid on postback too
(you can do this in Page_Load). Don't preselect the correct value
this time, the value will be restored from the postback automatically.

Then you can handle the postback (probably in the "UpdateCommand"
event).

Finally, you may bind the datagrid or list again, depending on what
you want to show after postback.
 
Hi,


Ensure that you dont refill your grid on postback. you can use page
ispostback to determine if your page called for the first time or its
postback call.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 
Back
Top