Introduction:
Here I will explain how to find or get text box value placed in gridview in asp.net or how to find controls (textbox, dropdownlist, checkbox,radio button etc..) in inside of asp.net gridview using c#.
Description:
In previous posts I explained bind data to textbox control in asp.net gridview, Cascading Dropdownlist in inside of asp.net gridview, populate one dropdown based on another dropdown in asp.net, bind data to dropdownlist in asp.net gridview and many articles relating to gridview, asp.net, c#. Now I will explain how to find or get text box value placed in gridview in asp.net.
In previous posts I explained bind data to textbox control in asp.net gridview, Cascading Dropdownlist in inside of asp.net gridview, populate one dropdown based on another dropdown in asp.net, bind data to dropdownlist in asp.net gridview and many articles relating to gridview, asp.net, c#. Now I will explain how to find or get text box value placed in gridview in asp.net.
Generally
if we want to find or get value from controls which is inside of gridview we
will write the code like as shown below
DropDownList ddl = (DropDownList)gvUserInfo.FindControl("yourControlName");
string
ddlValue = ddl.SelectedItem.Value;
TextBox
txtUserInfo = (TextBox)
gvUserInfo.FindControl("yourControlName");
string
strValue = txtUserInfo.Text;
|
In
case if we want to find controls inside gridview in rowdatabound condition we
will write code like this
protected void gvUserInfo_RowDataBound(object sender, GridViewRowEventArgs e)
{
DropDownList ddl = (DropDownList)gvUserInfo.FindControl("yourControlName");
string
ddlValue = ddl.SelectedItem.Value;
TextBox
txtUserInfo = (TextBox)
gvUserInfo.FindControl("yourControlName");
string
strValue = txtUserInfo.Text;
}
|
Suppose
if we have controls in each row of gridview then we need find each row of
controls for that we need to write a code like this
protected void gvUserInfo_RowDataBound(object sender, GridViewRowEventArgs e)
{
if
(e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddl = (DropDownList)e.Row.FindControl("ddlCity");
int
CountryId = Convert.ToInt32(ddl.SelectedItem);
}
}
|
If
you want to see it in example check below articles to bind controls in gridview
and get control values
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
0 comments :
Note: Only a member of this blog may post a comment.