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. Web Development
  3. ASP.NET
  4. Datagrid Row Update

Datagrid Row Update

Scheduled Pinned Locked Moved ASP.NET
databasedesignsysadminhelpquestion
10 Posts 3 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.
  • M Offline
    M Offline
    mccarthy111
    wrote on last edited by
    #1

    I have made a function to update data edited in a datagrid row. Here is the code: private void DiagnosisListDataGrid_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { int DiagnosisNo = (int) DiagnosisListDataGrid.DataKeys[(int) e.Item.ItemIndex]; string nino = ((TextBox)e.Item.Cells[3].Controls[0]).Text; string datetime = ((TextBox)e.Item.Cells[4].Controls[0]).Text; string details = ((TextBox)e.Item.Cells[5].Controls[0]).Text; string currentstatus = ((TextBox)e.Item.Cells[6].Controls[0]).Text; string sql = "UPDATE DIAGNOSIS SET NINo=?, [DateTime]=?, Details=?, currentStatus=? WHERE DiagnosisNo= ?"; DiagnosisListDataGrid.EditItemIndex = -1; OleDbConnection conn = new OleDbConnection( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("GeneralPractice/GeneralPractice.mdb")); OleDbCommand cmd = new OleDbCommand(sql, conn); cmd.Parameters.Add("NINo", nino); cmd.Parameters.Add("DateTime", datetime); cmd.Parameters.Add("Details", details); cmd.Parameters.Add("CurrentStatus", currentstatus); cmd.Parameters.Add("DiagnosisNo",DiagnosisNo); //ReadRecords(); conn.Open(); try { cmd.ExecuteNonQuery(); } finally { DiagnosisListDataGrid.DataBind(); if (conn != null) conn.Close(); } } The problem is that when the update button is cicked the datagrid disappears from the page. If it is loaded up again the info has been updated. Anyone know what am i'm missing out here? Rory

    S M 2 Replies Last reply
    0
    • M mccarthy111

      I have made a function to update data edited in a datagrid row. Here is the code: private void DiagnosisListDataGrid_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { int DiagnosisNo = (int) DiagnosisListDataGrid.DataKeys[(int) e.Item.ItemIndex]; string nino = ((TextBox)e.Item.Cells[3].Controls[0]).Text; string datetime = ((TextBox)e.Item.Cells[4].Controls[0]).Text; string details = ((TextBox)e.Item.Cells[5].Controls[0]).Text; string currentstatus = ((TextBox)e.Item.Cells[6].Controls[0]).Text; string sql = "UPDATE DIAGNOSIS SET NINo=?, [DateTime]=?, Details=?, currentStatus=? WHERE DiagnosisNo= ?"; DiagnosisListDataGrid.EditItemIndex = -1; OleDbConnection conn = new OleDbConnection( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("GeneralPractice/GeneralPractice.mdb")); OleDbCommand cmd = new OleDbCommand(sql, conn); cmd.Parameters.Add("NINo", nino); cmd.Parameters.Add("DateTime", datetime); cmd.Parameters.Add("Details", details); cmd.Parameters.Add("CurrentStatus", currentstatus); cmd.Parameters.Add("DiagnosisNo",DiagnosisNo); //ReadRecords(); conn.Open(); try { cmd.ExecuteNonQuery(); } finally { DiagnosisListDataGrid.DataBind(); if (conn != null) conn.Close(); } } The problem is that when the update button is cicked the datagrid disappears from the page. If it is loaded up again the info has been updated. Anyone know what am i'm missing out here? Rory

      S Offline
      S Offline
      Sebastien Lachance
      wrote on last edited by
      #2

      Have you set the datasource property of the datagrid ? This is something I think is missing. My Blog

      M 1 Reply Last reply
      0
      • M mccarthy111

        I have made a function to update data edited in a datagrid row. Here is the code: private void DiagnosisListDataGrid_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { int DiagnosisNo = (int) DiagnosisListDataGrid.DataKeys[(int) e.Item.ItemIndex]; string nino = ((TextBox)e.Item.Cells[3].Controls[0]).Text; string datetime = ((TextBox)e.Item.Cells[4].Controls[0]).Text; string details = ((TextBox)e.Item.Cells[5].Controls[0]).Text; string currentstatus = ((TextBox)e.Item.Cells[6].Controls[0]).Text; string sql = "UPDATE DIAGNOSIS SET NINo=?, [DateTime]=?, Details=?, currentStatus=? WHERE DiagnosisNo= ?"; DiagnosisListDataGrid.EditItemIndex = -1; OleDbConnection conn = new OleDbConnection( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("GeneralPractice/GeneralPractice.mdb")); OleDbCommand cmd = new OleDbCommand(sql, conn); cmd.Parameters.Add("NINo", nino); cmd.Parameters.Add("DateTime", datetime); cmd.Parameters.Add("Details", details); cmd.Parameters.Add("CurrentStatus", currentstatus); cmd.Parameters.Add("DiagnosisNo",DiagnosisNo); //ReadRecords(); conn.Open(); try { cmd.ExecuteNonQuery(); } finally { DiagnosisListDataGrid.DataBind(); if (conn != null) conn.Close(); } } The problem is that when the update button is cicked the datagrid disappears from the page. If it is loaded up again the info has been updated. Anyone know what am i'm missing out here? Rory

        M Offline
        M Offline
        mansir 123
        wrote on last edited by
        #3

        Try binding the data again to the datagrid after updating.

        M 1 Reply Last reply
        0
        • S Sebastien Lachance

          Have you set the datasource property of the datagrid ? This is something I think is missing. My Blog

          M Offline
          M Offline
          mccarthy111
          wrote on last edited by
          #4

          Would you be able to tell me how I can set the datasource property of my datagrid? Thanks

          1 Reply Last reply
          0
          • M mansir 123

            Try binding the data again to the datagrid after updating.

            M Offline
            M Offline
            mccarthy111
            wrote on last edited by
            #5

            When I enter the bind statement it doesn't help the problem?

            M 1 Reply Last reply
            0
            • M mccarthy111

              When I enter the bind statement it doesn't help the problem?

              M Offline
              M Offline
              mansir 123
              wrote on last edited by
              #6

              Jus check if after updating the data, did u bind the updated data to the datagrid.

              M 1 Reply Last reply
              0
              • M mansir 123

                Jus check if after updating the data, did u bind the updated data to the datagrid.

                M Offline
                M Offline
                mccarthy111
                wrote on last edited by
                #7

                After update I entered this statement to bind the data: DiagnosisListDataGrid.DataBind();

                S 1 Reply Last reply
                0
                • M mccarthy111

                  After update I entered this statement to bind the data: DiagnosisListDataGrid.DataBind();

                  S Offline
                  S Offline
                  Sebastien Lachance
                  wrote on last edited by
                  #8

                  Just before DiagnosisListDataGrid.DataBind(); add DiagnosisListDataGrid.DataSource = _dataset or datatable_; My Blog

                  M 2 Replies Last reply
                  0
                  • S Sebastien Lachance

                    Just before DiagnosisListDataGrid.DataBind(); add DiagnosisListDataGrid.DataSource = _dataset or datatable_; My Blog

                    M Offline
                    M Offline
                    mccarthy111
                    wrote on last edited by
                    #9

                    The datagrid still disappears when I run the command. I have a read records method which before I was trying to call, but when I called it it took two attempts two attempt of the update button click for the grid to be updated. Below is that method, if it can be used? private void ReadRecords() { OleDbConnection conn = null; OleDbDataReader reader = null; try { conn = new OleDbConnection( @"Provider=Microsoft.Jet.OLEDB.4.0; " + @"Data Source=" + Server.MapPath("GeneralPractice/GeneralPractice.mdb")); conn.Open(); OleDbCommand cmd = new OleDbCommand("Select * FROM DIAGNOSIS", conn); reader = cmd.ExecuteReader(); DiagnosisListDataGrid.DataSource = reader; DiagnosisListDataGrid.DataKeyField = "DiagnosisNo"; DiagnosisListDataGrid.DataBind(); } // catch (Exception e) // { // Response.Write(e.Message); // Response.End(); // } finally { if (reader != null) reader.Close(); if (conn != null) conn.Close(); } } Thanks

                    1 Reply Last reply
                    0
                    • S Sebastien Lachance

                      Just before DiagnosisListDataGrid.DataBind(); add DiagnosisListDataGrid.DataSource = _dataset or datatable_; My Blog

                      M Offline
                      M Offline
                      mccarthy111
                      wrote on last edited by
                      #10

                      The datagrid still disappears when I run the command. I have a read records method which before trying the code I gave, I was trying to call in the update method, but when I called it it took two attempts of the update button click for the grid to be updated. Below is that method, if it can be used? private void ReadRecords() { OleDbConnection conn = null; OleDbDataReader reader = null; try { conn = new OleDbConnection( @"Provider=Microsoft.Jet.OLEDB.4.0; " + @"Data Source=" + Server.MapPath("GeneralPractice/GeneralPractice.mdb")); conn.Open(); OleDbCommand cmd = new OleDbCommand("Select * FROM DIAGNOSIS", conn); reader = cmd.ExecuteReader(); DiagnosisListDataGrid.DataSource = reader; DiagnosisListDataGrid.DataKeyField = "DiagnosisNo"; DiagnosisListDataGrid.DataBind(); } // catch (Exception e) // { // Response.Write(e.Message); // Response.End(); // } finally { if (reader != null) reader.Close(); if (conn != null) conn.Close(); } } Thanks Rory

                      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