Grid View Selected Index
-
Hello Friends, I want to get the ID(unique field in "GridView3") respectively i click on the "Select" button or link. Here i'm giving my code. Plz check and make me correct. protected void GridView3_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { string str = GridView3.SelectedRow.Cells[1].Text; lblMsg.Text = str.ToString(); OR lblMsg.Text = GridView3.SelectedRow.RowIndex.ToString(); } But it throw(s) an error like Object reference not set to an instance of an object.
-
Hello Friends, I want to get the ID(unique field in "GridView3") respectively i click on the "Select" button or link. Here i'm giving my code. Plz check and make me correct. protected void GridView3_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { string str = GridView3.SelectedRow.Cells[1].Text; lblMsg.Text = str.ToString(); OR lblMsg.Text = GridView3.SelectedRow.RowIndex.ToString(); } But it throw(s) an error like Object reference not set to an instance of an object.
HI Knowledge! Actually I m not getting what exactly ur problem lies. Is label inside the Grid or Outside? do ur Source has the Unique Id that u r use to bind the grid? And yes About the Error : This Error Generally Arises when There is Unavailability of a Control.
Believe Yourself™ :->™
-
Hello Friends, I want to get the ID(unique field in "GridView3") respectively i click on the "Select" button or link. Here i'm giving my code. Plz check and make me correct. protected void GridView3_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { string str = GridView3.SelectedRow.Cells[1].Text; lblMsg.Text = str.ToString(); OR lblMsg.Text = GridView3.SelectedRow.RowIndex.ToString(); } But it throw(s) an error like Object reference not set to an instance of an object.
This event doesn't give you any selected row,you have to select row of the gridview as GridView3.SelectedIndex=e.NewSelectedIndex; GridView3.datasource=place here datatable GridView3.databind() place ur code in the following event. I think your problem will be solved. protected void GridView3_SelectedIndexChanged(object sender, EventArgs e) { string str = GridView3.SelectedRow.Cells[1].Text; lblMsg.Text = str.ToString(); OR lblMsg.Text = GridView3.SelectedRow.RowIndex.ToString(); }