VB.Net Gridview Dropdownlist SelectedValue in ASP.Net

Selected Value of nested ASP.Net Dropdownlist control placed inside the ItemTemplate of TemplateField column of GridView requires VB.Net foreach loop to bind the data with each Dropdownlist control and set their SelectedValue. The FindControl method provides the functionality to find the control placed inside the ItemTemplate of GridView control and get its reference in VB.Net code behind. DataKeys array collection associated to the DataKeyNames property of GridView control enables you to get the values saved in the database that is to be set as selectedvalue of each Dropdownlist control.

 

VB.Net Elements Used

1. for each loop

2. FindControl method

3. DataKeys array collection

 

The VB.Net For Each loop enables to get the reference to each object contained inside the specified collection. For example each GridViewRow item of the GridView control. The VB.Net FindControl methods accepts a string value as an ID of the control that is to be accessed inside the parent control. The DataKeys array collection provides the value of the Data field specified for each row of gridview control using its DataKeyNames property.

 

Try the sample below to understand the functionality for binding the data and setting the selectedvalue property of the Dropdownlist control placed inside the ASP.Net GridView contol using VB.Net code:

 

OrderIDOrder Status
1
2
3
4

  • HIRE EzineASP.Net Developers