472,344 Members | 1,244 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,344 software developers and data experts.

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)

Expand|Select|Wrap|Line Numbers
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3. if (!IsPostBack)
  4. {
  5. NewGame(0); 
  6. }
  7. else
  8. {
  9. lblStatus.Text = lblStatus.Text + "postback!";
  10. //DataRow[] currentRows = mySet.Tables["numberset"].Select(null, null, DataViewRowState.CurrentRows);
  11. mySet = _newGame.GameSet;
  12. DataRow[] currentRows = mySet.Tables["problemcopyset"].Select(null, null, DataViewRowState.CurrentRows);
  13. foreach (DataRow row in currentRows)
  14. {
  15. foreach (DataColumn column in mySet.Tables["problemcopyset"].Columns)
  16. {
  17. lblStatus.Text = lblStatus.Text + row[column] ; //+ "(" + ;
  18. }
  19. ////lblStatus.Text = lblStatus.Text + row.RowState;
  20. }
  21. lblStatus.Text = lblStatus.Text + "
  22. ";
  23. }
  24. }
  26. private void NewGame(int index)
  27. {
  28. GameLevel[] levels = { GameLevel.SIMPLE, GameLevel.MEDIUM, GameLevel.COMPLEX };
  31. if (index > -1)
  32. {
  33. _newGame.GenerateGame(levels[index]);
  34. gameGrid.Visible = false;
  35. _currentSet = _newGame.GameSet;
  36. mySet = _currentSet;
  37. _currentSet.Tables["numberset"].DefaultView.AllowNew = false;
  38. //_currentSet.Tables["numberset"].Columns["numbersets_Id"].ReadOnly = true;
  41. if (_currentSet != null)
  42. {
  43. _currentSet.Tables["answerset"].ColumnChanging += new DataColumnChangeEventHandler(this.CurrentSet_ColumnChanging);
  44. //DataRow[] currentRows = _currentSet.Tables["numberset"].Select(null, null, DataViewRowState.CurrentRows);
  45. }
  46. gameGrid.Visible = true;
  47. gameGrid.DataSource = _currentSet.Tables["numberset"];
  48. gameGrid.DataBind();
  50. }
  53. }
  54. protected void gameGrid_RowEditing(object sender, GridViewEditEventArgs e)
  55. {
  56. lblStatus.Text = lblStatus.Text + "
  57. editing!
  58. ";
  59. gameGrid.EditIndex = e.NewEditIndex;
  60. gameGrid.DataSource = mySet.Tables["numberset"];
  61. gameGrid.DataBind();
  62. }
Any help would be greatly appreciated.

Nov 28 '06 #1
0 3258

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Nalaka | last post by:
Hi, I have a gridView (grid1), which as a templateColumn. In the template column, I have put in a gridView (grid2) and a ObjectDataSource...
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that...
by: Jim Katz | last post by:
I have an application that updates a strongly typed data set at run time. I'd like to dynamically create a table that connects to a run time data...
by: Dick | last post by:
I have a GridView bound to an ObjectDataSource. I have a Button that calls GridView.DataBind. I want the row that is selected before the DataBind to...
by: NKaufman | last post by:
<asp:GridView ID="Basic" runat="server" DataKeyNames="QuestionID,isHeading" AutoGenerateColumns="false" AllowPaging="true" PageSize="100">...
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
I have a vb.net 2.0 app that is loading a GridView with a DataSource that is returned from a function. The definitions in the function are: ...
by: mohaaron | last post by:
This seems like it should be simple to do but for some reason I have been unable to make it work. I would like to databind a SqlDataSource to a...
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have a gridview with several template columns and a few command button columns, column 1 and 2 are dropdown boxes, column 3 is a checkbox and...
by: =?Utf-8?B?U0FM?= | last post by:
I am trying to cast my Gridview in my Code behide as a Dataset so I can manipulate the data. Here is the code snippet: Dim FilteredDataSet As New...
by: Peter | last post by:
I have a GridView which is populated by List<ofObjects> Does anyone have example of how to sort the columns of this GridView? I have found...
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.