Introduction:
In this article I will explain how to find controls (textbox, dropdownlist, checkbox,radio button etc..) in inside of gridview and how to get values from controls which is inside of gridview in rowdatabound condition in asp.net.
In this article I will explain how to find controls (textbox, dropdownlist, checkbox,radio button etc..) in inside of gridview and how to get values from controls which is inside of gridview in rowdatabound condition in asp.net.
Description:
In previous posts I explained many articles relating to gridview now I will explain how to find or get values of controls which is inside of gridview in asp.net.
In previous posts I explained many articles relating to gridview now I will explain how to find or get values of controls which is inside of gridview in asp.net.
Generally if we want to find or get value from
controls which is inside of 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);
}
}
|
For sample or example check
below posts
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. |
|||
|
|||
15 comments :
you are using dropdown list can u please show in gridview
great,, thanks,,,
work for me.. thanks a loott
sir can you provide a demo for nested gridview And load data into it from sql in C#?
thanks.Nice one
Hi suresh i want to find span id in row databond is it possible to find that
@Anonymous
You can get the span id in rowdatabound event by defining control there as HtmlGenericControl.
var spanid = e.item.FindControl("") as HtmlGenericControl
want to use multiple fileupload control againtst each row inside gridview and save files to database on Submitt click....please help
it is a wonderful site. please keep uploading new articles.
thanks.
have a great time.
good
nice..........
i want the value of textbox in rowdatabound event but the control is on a page, not inside the gridview.....
Label bill = (Label)e.Row.FindControl("lbl_bill");
nice sir
I want to make invoice system
plz suggest me how i can make ?
window based C#
Great coding
Hi guys and suresh ,I need one help im getting one error .This is an application error.
The error is
Unable to find control id 'TextBox1' referenced by the 'ControlToValidate' property of 'RangeFieldValidator1".
how do i solve this please give me some suggestions do i need to refer this id in master page.
Note: Only a member of this blog may post a comment.