Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 28th, 2006, 02:54 PM
Authorized User
 
Join Date: Jul 2006
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Default GridView DataSource

Hi,

I am working on a GridView control to play a game. I am trying to make the cells editable; however, when I click on edit I lost my data or I get an error:

Object reference not set to an instance of an object

Here is a code sample (excuse the messiness, I am still debugging things and I like to clean-up at the end)


Code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
NewGame(0); 
}
else
{
lblStatus.Text = lblStatus.Text + "postback!";
//DataRow[] currentRows = mySet.Tables["numberset"].Select(null, null, DataViewRowState.CurrentRows);
mySet = _newGame.GameSet;
DataRow[] currentRows = mySet.Tables["problemcopyset"].Select(null, null, DataViewRowState.CurrentRows);
foreach (DataRow row in currentRows)
{
foreach (DataColumn column in mySet.Tables["problemcopyset"].Columns)
{
lblStatus.Text = lblStatus.Text + row[column] ; //+ "(" + ;
}
////lblStatus.Text = lblStatus.Text + row.RowState;
}
lblStatus.Text = lblStatus.Text + "
";
}
}

private void NewGame(int index)
{
GameLevel[] levels = { GameLevel.SIMPLE, GameLevel.MEDIUM, GameLevel.COMPLEX };


if (index > -1)
{
_newGame.GenerateGame(levels[index]);
gameGrid.Visible = false;
_currentSet = _newGame.GameSet;
mySet = _currentSet;
_currentSet.Tables["numberset"].DefaultView.AllowNew = false;
//_currentSet.Tables["numberset"].Columns["numbersets_Id"].ReadOnly = true;


if (_currentSet != null)
{
_currentSet.Tables["answerset"].ColumnChanging += new DataColumnChangeEventHandler(this.CurrentSet_ColumnChanging);
//DataRow[] currentRows = _currentSet.Tables["numberset"].Select(null, null, DataViewRowState.CurrentRows);
}
gameGrid.Visible = true;
gameGrid.DataSource = _currentSet.Tables["numberset"];
gameGrid.DataBind();

}


}
protected void gameGrid_RowEditing(object sender, GridViewEditEventArgs e)
{
lblStatus.Text = lblStatus.Text + "
editing!
";
gameGrid.EditIndex = e.NewEditIndex;
gameGrid.DataSource = mySet.Tables["numberset"];
gameGrid.DataBind();
}
Any help would be greatly appreciated.

Thanks!







Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting GridView with a Collection as DataSource+ danielpilon C# 7 June 10th, 2008 04:20 PM
Disp Footer even no record in GridView Datasource mallikalapati ASP.NET 2.0 Professional 1 March 19th, 2008 02:23 AM
chapter about object datasource and gridview? asptwodev BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 1 November 2nd, 2007 12:53 PM
Gridview for inser,update without using datasource karthikeyan_pa ASP.NET 2.0 Professional 0 September 4th, 2007 07:58 AM
Gridview Sorting Event without a Datasource rit01 ASP.NET 2.0 Professional 15 March 22nd, 2007 03:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.