Please disable your adblock and script blockers to view this page
 

How to find TextBox, DropDownList or other controls in Gridview in asp.net

Introduction: In previous articles i explained How to find TextBox, DropDownList or other controls in Gridview ‘s RowDataBound event of in asp.net .While working on website we sometimes require to find TextBox, DropDownList or other controls placed inside GridView so that we can get their value and update if needed.In this article i have tried to explain how to  find TextBox, DropDownList or other controls in GridView in asp.net

Suppose you have a GridView grdEmp  and you want to find a control e.g TextBox or DropDownList placed inside the GridView on RowUpdating 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 in asp.net

protected void grdEmp_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        DropDownList ddlDept = (DropDownList)grdEmp.Rows[e.RowIndex].FindControl("ddlGrdDept");

        TextBox txtcity = (TextBox)grdEmp.Rows[e.RowIndex].FindControl("txtCity");
    }

VB.Net Code to find TextBox, DropDownList or other controls in Gridview in asp.net
Protected Sub grdEmp_RowUpdating(sender As Object, e As GridViewUpdateEventArgs)
                    Dim ddlDept As DropDownList = DirectCast(grdEmp.Rows(e.RowIndex).FindControl("ddlGrdDept"), DropDownList) 
                    Dim txtcity As TextBox = DirectCast(grdEmp.Rows(e.RowIndex).FindControl("txtCity"), TextBox)
End Sub
 
Previous
Next Post »

1 comments:

Click here for comments
October 02, 2013 ×

how to retrieve the data of check box list in grid view or any other view??

Congrats bro Mr.M.Prasant Kumar you got PERTAMAX...! hehehehe...
Reply
avatar

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