GridView and SelectedIndexChanged
-
Hi!!
public void GridView2_SelectedIndexChanged(Object sender, EventArgs e) { TextBox tb = GridView2.SelectedRow.FindControl("id0") as TextBox; if (tb != null) TextBox1.Text = tb.Text; else TextBox1.Text = "no data"; //TextBox1.Text = GridView2.SelectedRow.Cells[1].Text; }
This code returns me always "no data" even if there is data in the GridView. I do not see where is the error. thanks -
Hi!!
public void GridView2_SelectedIndexChanged(Object sender, EventArgs e) { TextBox tb = GridView2.SelectedRow.FindControl("id0") as TextBox; if (tb != null) TextBox1.Text = tb.Text; else TextBox1.Text = "no data"; //TextBox1.Text = GridView2.SelectedRow.Cells[1].Text; }
This code returns me always "no data" even if there is data in the GridView. I do not see where is the error. thanksfor what purpose ur using the selectionchange event.may be it cant get the template inside the gridview.try it in rowcommand event i think it will work
-
Hi!!
public void GridView2_SelectedIndexChanged(Object sender, EventArgs e) { TextBox tb = GridView2.SelectedRow.FindControl("id0") as TextBox; if (tb != null) TextBox1.Text = tb.Text; else TextBox1.Text = "no data"; //TextBox1.Text = GridView2.SelectedRow.Cells[1].Text; }
This code returns me always "no data" even if there is data in the GridView. I do not see where is the error. thanksTry debugging, that helps. I guess the .FindControl is not finding your "id0", and for a reason. Imagine you're looking for something, but it's there in front of you, just locked in a box. Your textbox is in a cell of your .SelectedRow, now I can only assume by your commented-out code it's the first cell. so do:
TextBox tb = GridView2.SelectedRow.Cells[1].FindControl("id0") as TextBox;
and it should be fine.
var question = (_2b || !(_2b));
-
Try debugging, that helps. I guess the .FindControl is not finding your "id0", and for a reason. Imagine you're looking for something, but it's there in front of you, just locked in a box. Your textbox is in a cell of your .SelectedRow, now I can only assume by your commented-out code it's the first cell. so do:
TextBox tb = GridView2.SelectedRow.Cells[1].FindControl("id0") as TextBox;
and it should be fine.
var question = (_2b || !(_2b));
Thank you Satish Mahapatra and Greg Chelstowski. I tried your solution but it does not work:( I want to have: the value of a cell of selected line in a GridView. I read that i can do that :TextBox1.Text = GridView2.SelectedRow.Cells[1].Text; but it doesn't work.