Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Get Find control inside of asp.net gridview in rowdatabound event

Jun 18, 2012
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.

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.
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.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

13 comments :

Anonymous said...

nice

Anonymous said...

you are using dropdown list can u please show in gridview

Anonymous said...

great,, thanks,,,
work for me.. thanks a loott

Vichusrk vp said...

sir can you provide a demo for nested gridview And load data into it from sql in C#?

Anonymous said...

thanks.Nice one

Anonymous said...

Hi suresh i want to find span id in row databond is it possible to find that

Dhaval Vaghani said...

@Anonymous

You can get the span id in rowdatabound event by defining control there as HtmlGenericControl.

var spanid = e.item.FindControl("") as HtmlGenericControl

Sudhakar said...

want to use multiple fileupload control againtst each row inside gridview and save files to database on Submitt click....please help

Anonymous said...

it is a wonderful site. please keep uploading new articles.
thanks.
have a great time.

Anonymous said...

good

Siva Raj said...

nice..........

Atul Pethe said...

i want the value of textbox in rowdatabound event but the control is on a page, not inside the gridview.....

pabitra behera said...

Label bill = (Label)e.Row.FindControl("lbl_bill");
nice sir

Give your Valuable Comments

Other Related Posts

© 2010-2012 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.