0% found this document useful (0 votes)
15 views

Findcontrols in Grdiview For Particular Row: Gridviewrow Label Label Label Textbox Textbox Textbox

The document discusses finding and accessing controls within rows of a GridView control in ASP.NET. It describes using the FindControl method to retrieve Label and TextBox controls from a selected row. It also covers retrieving data keys from the GridView's DataKeys collection using the row index or selected index, such as the ID value associated with a selected row. The DataKeys collection stores additional data associated with each row that isn't bound as a field.

Uploaded by

tbijle
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Findcontrols in Grdiview For Particular Row: Gridviewrow Label Label Label Textbox Textbox Textbox

The document discusses finding and accessing controls within rows of a GridView control in ASP.NET. It describes using the FindControl method to retrieve Label and TextBox controls from a selected row. It also covers retrieving data keys from the GridView's DataKeys collection using the row index or selected index, such as the ID value associated with a selected row. The DataKeys collection stores additional data associated with each row that isn't bound as a field.

Uploaded by

tbijle
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Findcontrols

In grdiview
For particular row
GridViewRow row = gridCategory.Rows[gridCategory.SelectedIndex];
Label lblnam = (Label)(row.FindControl("lblname") as Label);
TextBox txtVar=(TextBox )(row .FindControl ("TextBox1") as TextBox) ;
txtcategoryname.Text = lblnam.Text;

onbutton click Rowwise inside the gridview findcontrol Method


int rowindex = ((sender as Button).NamingContainer as GridViewRow).RowIndex;
int id = Convert.ToInt32(GridView1.DataKeys[rowindex].Values[0]);
for gridview select IndexChanged event
protected void GridView1_SelectedIndexChanged(Object src, EventArgs e)
{
string Description = GridView1.DataKeys[GridView1.SelectedIndex].
Values["AccountDescription"].ToString();
}

GridView control stores data keys as a collection and this collection is called the DataKeys collection.
This DataKeys collection is exposed by the GridView control's DataKeys property. We retrieve the data
key associated with a selected row by using the statement:
string id = GridView1.DataKeys[GridView1.SelectedIndex].Value.ToString();
This statement returns the value of the data key associated with the selected row of the gridView
control.
Here, we have assigned multiple data keys to DataKeyNames property. So we can use a statement
that looks like this:

You might also like