DropdownList in EditTemplate

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!
 
J

Jos

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.
 
N

Natty Gur

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top