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:
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>
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)
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
1 comments:
Click here for commentshow to retrieve the data of check box list in grid view or any other view??
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..