Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. GridView losing its dataset

GridView losing its dataset

Scheduled Pinned Locked Moved C#
helpdatabasegame-dev
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Abbas82
    wrote on last edited by
    #1

    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) 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!

    E 1 Reply Last reply
    0
    • A Abbas82

      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) 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!

      E Offline
      E Offline
      ednrgc
      wrote on last edited by
      #2

      This looks like an ASP.NET problem. Am I correct? If so, it looks like you're not caching your dataset between postbacks.

      A 1 Reply Last reply
      0
      • E ednrgc

        This looks like an ASP.NET problem. Am I correct? If so, it looks like you're not caching your dataset between postbacks.

        A Offline
        A Offline
        Abbas82
        wrote on last edited by
        #3

        Yes, you are right...I managed to get it to work. Thanks!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups