1

for gridviews, how can i get the cell values as well as column names from it when click on a button and this button sometimes can be embedded within a gridview row also can be outside the gridview somewhere else on the page. my stupid and simple way is to find the control of the gridview columns by creating each column as a label type on client side. so it's something on the server side for getting the text values like,

Label lblName = (Label) gvName.Rows[gvName.RowIndex].FindControl("lblSomeContent")

It's fine when it's only few columns, but what if there are more than ten different columns, should I do this again and again for ten times? is there any better way? I tried to loop through each gridview.rows but it always contains empty values, which I do not know why.

Tiger
  • 139
  • 1
  • 3
  • 12

1 Answers1

1

what you can do you can create an instance of grid row
And then you can use find control.

GridViewRow gRow=gvName.Rows[gvName.RowIndex];

and then use find control

Label lblName = (Label)gRow.FindControl("lblSomeContent");

Similarly other controls

TextBox textBox=(TextBox)gRow.FindControl("txtSomeContent");
शेखर
  • 17,412
  • 13
  • 61
  • 117