Skip Navigation LinksHome > Categories > Code from a Category keep the dropdownlist value selected when Edit a gridview row

User Name: jamest85
Name: James Tang
Contact Me:
Home Page:
Google Apps for Work Partner, Certified Zoho CRM Consultant. 7 years experience on Zoho consulting, implementation, and programming using C#, VB, Php..., 15 years of total IT experience including prog... [More]
Viewed Times: 5371
Add Date: 05/07/2010
Sometime we want to add a Dropdownlist control in our gridview (or datalist...), and let the Dropdownlist value matches with the data from the database table. for example, if in the table, a column value only accept 1 or 0, and you want to show Yes/No in the dropdown list.
Note: In above html code, we added a hidden label, and Eval() the value from datasource, that can help the Dropdownlist to select correct value.
Also in the [ItemTemplate] section, we added a function call showYesOrNo(), and that function can be implemented from code behind: That wasn't too hard, but we also need take care the dropdonwlist when user clicks the "Edit" Link button, otherwise, once the "Edit" Link button is clicked, the dropdownlist won't show the original yes/no value, and will jump to the first item in the list, in here, it will jump to the empty item, that will confuse the user.
By the way, since we leave an empty text item in the dropdownlist, if user didn't select yes/no value, will send an error message to the user: Above is an simple example, but can be used in pretty complex situations, such as: there are a lot of dowpdownlist items, and the items' value and text are also vary...
Comment #:  146 Replay this Comment Reply this comment Posted on: 8/3/2013

 Hello! I am programming in vb, could you help me translate that c# to vb please? I have that exact problem and i think that's the solution, but i can't properly write the code in vb.. :/

Post a Comment

Name: (Optional)
Email: (Optional, you can get an email if somebody replys your comments)*
Email me if somebody respons my comment below:
Enter Text
as Below:
(case insensitive, if hard to read, click the "get a new one" button)
* Your email address will not be shared with any third parties for any reason.
** Maximum 1000 charactors.