Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 28th, 2006, 02:54 PM
Authorized User
Join Date: Jul 2006
Location: , , .
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Default GridView DataSource


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)

protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
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)
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"];


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



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 02:11 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.