473,396 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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)


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. }
  25.  
  26. private void NewGame(int index)
  27. {
  28. GameLevel[] levels = { GameLevel.SIMPLE, GameLevel.MEDIUM, GameLevel.COMPLEX };
  29.  
  30.  
  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;
  39.  
  40.  
  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();
  49.  
  50. }
  51.  
  52.  
  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.

Thanks!
Nov 28 '06 #1
0 3293

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

Similar topics

6
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 (objectDataSource2). Question is... How to I pass the...
7
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 works fine when I populate it with data. Now I...
4
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 table. For displaying the data, this works well. ...
5
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 still be selected afterwards. This happens...
5
by: NKaufman | last post by:
<asp:GridView ID="Basic" runat="server" DataKeyNames="QuestionID,isHeading" AutoGenerateColumns="false" AllowPaging="true" PageSize="100"> <Columns> <asp:BoundField Visible="false"...
4
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: Dim ReportDS As DataSet = New DataSet Dim...
4
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 GridView during the click event of a button. This...
3
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 column 4 is a text box, followed by command button...
7
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 System.Data.DataSet Dim gv As New GridView gv...
3
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 examples without DataSourceControl but these use...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.