Dear I have just started .net asp 2.0 with Web Developer Express edition no previous background of .net.
I have a table accessories with 10 columns in it and I am show only two in gridview (tabular form) i add a button control which is not bound to any data item in table.
What I want that when user click on that button another form should popup and user could do operations like add, edit, delete there. Fot that purpose i need to get the value of primary key of current row. I search in already available solutions and found a way to do it which is
Session["ww"] = GridView1.SelectedRow.Cells.Text;
but when i run this line system give an error because no row is selected so SelectedRow is set to null in debug window.
I dont know that how i can make this row selected which is my current row already.
and the following method is call on that row on click event as:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
Session["ww"] = GridView1.SelectedRow.Cells.Text; --- Error generate on this row.
Folowing is the error detail :
System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
at ASP.accessories_aspx.GridView1_RowCommand(Object sender, GridViewCommandEventArgs e) in c:\Documents and Settings\Owner.HOME\My Documents\Visual Studio 2005\WebSites\MicroHardOnline\Accessories.aspx:line 29
at System.Web.UI.WebControls.GridView.OnRowCommand(GridViewCommandEventArgs e)
at System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup)
at System.Web.UI.WebControls.GridView.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.GridView.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)