473,715 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView DataSource

5 New Member

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 3304

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 (objectDataSource2). Question is... How to I pass the current_row_key of Grid1... to the objectDataSource2 parameter? (so that the second grid, gets only the information to do with current row of grid1)
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 want to look at that data and filter it based on what is in it. I know that this could have been done with data sets and data views in asp.net 1.1 but how is this done now in asp.net 2.0?
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. I just set the GridView.DataSource once, and call DataBind(); I'd like to drive the application from the GridView control, by including command buttons that allow editing of the data. Starting out simple, I have a DataTable with a boolean...
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 automatically if the data doesn't change. But if records have been added or deleted then it looks as if some code is necessary: I've done this by using GridView.SelectedValue to get the key value of the currently selected Row and then by itterating...
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" DataField="QuestionID" HeaderText="QuestionID"></asp:BoundField> <asp:BoundField DataField="QuestionDesc" HeaderText="Question" ItemStyle-HorizontalAlign="Left"></ asp:BoundField>
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 ReportTable As System.Data.DataTable = New System.Data.DataTable("SendTo") The ReportTable is populated row by row by data gotten back from the
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 sounds easy but the next requirement is that the GridView is editable. So I have included the SelectCommand and the UpdateCommand on the SqlDataSource to allow the GridView to be editable. I have now been able to get the GridView to display data...
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 columns. These are all for data entry and although I am populating the dropdown list boxes with an objectdatasource so the user can provide a selection, I am not binding the gridview to anything. The command buttons again are for the user to be...
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 = CType(tbl_ReportData.FindControl("GridView_1"), GridView) gv.GridLines = GridLines.Both gv.DataBind() FilteredDataSet = DirectCast(gv.DataSource, System.Data.DataSet)
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 DataTable, I am using List of Objects. Here's one example: http://ryanolshan.com/technology/gridview-without-datasourcecontrol-datasource/
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.