Please disable your adblock and script blockers to view this page
 

How to find TextBox, DropDownList or other controls in Gridview ‘s RowDataBound event of in asp.net

Introduction: In previous articles in explained How to find TextBox, DropDownList or other controls in Gridview in asp.net and How to bind gridview using SqlDataAdapter, DataTable and Stored procedure in Sql server and  How to bind empty GridView with header and custom message when no data present in Datatable in Asp.net
 Now in this article i will explain how to find other controls like TextBox, DropDownList etc placed inside Gridview .

Suppose you have a GridView grdEmp  and you want to find a control e.g. TextBox, DropDownList inside the GridView on RowDataBound event then here is the code:

<asp:GridView ID="grdEmp" runat="server" >
</GridView> 

C#.Net Code to find TextBox, DropDownList or other controls in Gridview ‘s RowDataBound event


   protected void grdEmp_RowDataBound(object sender, GridViewRowEventArgs e)
    {
DropDownList ddlGrd=(DropDownList)(e.Row.FindControl("ddlGrdDept"));
                TextBox txtEmpName = (TextBox)e.Row.FindControl("txtEmpName");
    }

VB.Net Code to find TextBox,DropDownList or other controls in Gridview ‘s RowDataBound event

Protected Sub grdEmp_RowDataBound(sender As Object, e As GridViewRowEventArgs)
                Dim ddlGrd As DropDownList = DirectCast(e.Row.FindControl("ddlGrdDept"), DropDownList)
                Dim txtEmpName As TextBox = DirectCast(e.Row.FindControl("txtEmpName"), TextBox)
End Sub

Previous
Next Post »

If you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily.. ConversionConversion EmoticonEmoticon