N
needin4mation
In this code:
protected void GridView1_RowCreated(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView rowView = (DataRowView)e.Row.DataItem;
// Retrieve the value for the current row.
string idValue = rowView["id"].ToString();
//do more stuff
}
}
This code works when I run my gridview, but as soon as I try and go to
the second page I get an error in Visual Studio that says:
Use the "new" keyword to create and object reference
Check to determine if the object is null before calling the method
Here is what is copied to the clipboard from VS:
System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="App_Web_fiaeux3t"
StackTrace:
at test.GridView1_RowCreated(Object sender, GridViewRowEventArgs
e) in c:\websites\BootStore\test.aspx.cs:line 27
at
System.Web.UI.WebControls.GridView.OnRowCreated(GridViewRowEventArgs e)
at System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex,
Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState
rowState, Boolean dataBind, Object dataItem, DataControlField[] fields,
TableRowCollection rows, PagedDataSource pagedDataSource)
at
System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable
dataSource, Boolean dataBinding)
at
System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls()
at System.Web.UI.Adapters.ControlAdapter.CreateChildControls()
at System.Web.UI.Control.EnsureChildControls()
at
System.Web.UI.WebControls.CompositeDataBoundControl.get_Controls()
at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList
childState)
at System.Web.UI.Control.LoadViewStateRecursive(Object
savedState)
at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList
childState)
at System.Web.UI.Control.LoadViewStateRecursive(Object
savedState)
at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList
childState)
at System.Web.UI.Control.LoadViewStateRecursive(Object
savedState)
at System.Web.UI.Page.LoadAllState()
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
I know there is data in the second page and it has an id value. I have
run it without the statement above to verify it. Just blows up on each
hit to anything but the first page.
Thank you for any help.
protected void GridView1_RowCreated(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView rowView = (DataRowView)e.Row.DataItem;
// Retrieve the value for the current row.
string idValue = rowView["id"].ToString();
//do more stuff
}
}
This code works when I run my gridview, but as soon as I try and go to
the second page I get an error in Visual Studio that says:
Use the "new" keyword to create and object reference
Check to determine if the object is null before calling the method
Here is what is copied to the clipboard from VS:
System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="App_Web_fiaeux3t"
StackTrace:
at test.GridView1_RowCreated(Object sender, GridViewRowEventArgs
e) in c:\websites\BootStore\test.aspx.cs:line 27
at
System.Web.UI.WebControls.GridView.OnRowCreated(GridViewRowEventArgs e)
at System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex,
Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState
rowState, Boolean dataBind, Object dataItem, DataControlField[] fields,
TableRowCollection rows, PagedDataSource pagedDataSource)
at
System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable
dataSource, Boolean dataBinding)
at
System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls()
at System.Web.UI.Adapters.ControlAdapter.CreateChildControls()
at System.Web.UI.Control.EnsureChildControls()
at
System.Web.UI.WebControls.CompositeDataBoundControl.get_Controls()
at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList
childState)
at System.Web.UI.Control.LoadViewStateRecursive(Object
savedState)
at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList
childState)
at System.Web.UI.Control.LoadViewStateRecursive(Object
savedState)
at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList
childState)
at System.Web.UI.Control.LoadViewStateRecursive(Object
savedState)
at System.Web.UI.Page.LoadAllState()
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
I know there is data in the second page and it has an id value. I have
run it without the statement above to verify it. Just blows up on each
hit to anything but the first page.
Thank you for any help.