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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Gridview problem

Gridview problem

Scheduled Pinned Locked Moved ASP.NET
helpdatabasequestion
2 Posts 2 Posters 1 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.
  • J Offline
    J Offline
    jpmadeira
    wrote on last edited by
    #1

    I'm having a lot of problems with the gridview bind. I have a dataset that represents a table of a database. When I delete or insert a row in the gridview I have the data well inserted or deleted in the db but the gridview duplicates the rows when postbacks the page and i can't understand why. Can someone help me? Code aspx.cs: protected void Page_Load(object sender, EventArgs e) { dbHandler = new WalletManagerDBSqlSrvHandler(DB_SERVER); shoptype_grid.DataSource = dbHandler.getShopTypes().Tables["ShopType"]; if (!Page.IsPostBack) { shoptype_grid.DataBind(); } formatShopTypeGrid(); } //eventhandler when a row is inserted protected void onClickInsertShopType(object sender, EventArgs e) { DataTable dtable = dbHandler.getShopTypes().Tables["ShopType"]; DataRow dataRow = dtable.NewRow(); dataRow["ID"] = DateTime.UtcNow.Ticks; /*Generates the ID of the inserted item threw the date and time tick*/ dataRow["Type"] = shopType_txtbox.Text; dtable.Rows.Add(dataRow); dbHandler.updateShopType(DatabaseOperation.Insert); shoptype_grid.DataBind(); } //eventhandler when a row is deleted protected void shoptype_grid_RowDeleting(object sender, GridViewDeleteEventArgs e) { DataTable dtable = dbHandler.getShopTypes().Tables["ShopType"]; DataRow drow = dtable.Rows[e.RowIndex]; drow.Delete(); //row erased dbHandler.updateShopType(DatabaseOperation.Delete); shoptype_grid.DataBind(); }

    I'm a Worm Bug ;)

    C 1 Reply Last reply
    0
    • J jpmadeira

      I'm having a lot of problems with the gridview bind. I have a dataset that represents a table of a database. When I delete or insert a row in the gridview I have the data well inserted or deleted in the db but the gridview duplicates the rows when postbacks the page and i can't understand why. Can someone help me? Code aspx.cs: protected void Page_Load(object sender, EventArgs e) { dbHandler = new WalletManagerDBSqlSrvHandler(DB_SERVER); shoptype_grid.DataSource = dbHandler.getShopTypes().Tables["ShopType"]; if (!Page.IsPostBack) { shoptype_grid.DataBind(); } formatShopTypeGrid(); } //eventhandler when a row is inserted protected void onClickInsertShopType(object sender, EventArgs e) { DataTable dtable = dbHandler.getShopTypes().Tables["ShopType"]; DataRow dataRow = dtable.NewRow(); dataRow["ID"] = DateTime.UtcNow.Ticks; /*Generates the ID of the inserted item threw the date and time tick*/ dataRow["Type"] = shopType_txtbox.Text; dtable.Rows.Add(dataRow); dbHandler.updateShopType(DatabaseOperation.Insert); shoptype_grid.DataBind(); } //eventhandler when a row is deleted protected void shoptype_grid_RowDeleting(object sender, GridViewDeleteEventArgs e) { DataTable dtable = dbHandler.getShopTypes().Tables["ShopType"]; DataRow drow = dtable.Rows[e.RowIndex]; drow.Delete(); //row erased dbHandler.updateShopType(DatabaseOperation.Delete); shoptype_grid.DataBind(); }

      I'm a Worm Bug ;)

      C Offline
      C Offline
      C Mahesh
      wrote on last edited by
      #2

      I think you should clear the view before updating.

      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