GridView Find hiddenfield and dropdownlist in rowdatabound event

By bryan tugade

Finding controls like hiddenfield, dropdownlist inside gridview on rowdatabound event and assign the value of hiddenfield in the dropdownlist bound in SqlDataSource.

Assuming that you already bind the dropdownlist in SqlDataSource inside the gridview. And you also bind the hiddenfield with data that needs to pass in the dropdownlist  to show the assigned value.

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        'bind("coursecode")
        If e.Row.RowType = DataControlRowType.DataRow Then

             Dim HiddenField1 As HiddenField = CType(e.Row.FindControl("HiddenField1"), HiddenField)
    
            Dim DropDownList1 As DropDownList = CType(e.Row.FindControl("DropDownList1"), DropDownList)
      
            DropDownList1.SelectedValue = HiddenField1.Value
          
        End If
    End Sub

That's it! Happy coding.

Related FAQs

In C#, we can select and deselect checkbox in gridview in onPostback event of checkbox in gridview header.
This topic will show us on how to search a data in a database using SqlMethods.Like in Linq to Sql
We can select multiple fields in a given database tables using Linq to sql. I use AdventureWorks as my database in this sample app and to show you how it works i bind the results in gridview control.
This topic will show us on how to find data that starts with a given character using StartsWith function in Linq to Sql.
We can hover on gridview row using javascript onmouseover event. We can also change the color in code behind.
We can filter data using dataview.
GridView Find hiddenfield and dropdownlist in rowdatabound event  (2789 Views)