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 EditCommand

DataGrid EditCommand

Scheduled Pinned Locked Moved ASP.NET
helpcsharpannouncement
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.
  • P Offline
    P Offline
    princy10
    wrote on last edited by
    #1

    Hi, I'm using .net 2008.i've a datagrid named 'dgUserNote'. I add edit,cancel,upadte and delete like this; and in coding part i written like; void dgUserNote_EditCommand(object source, DataGridCommandEventArgs e) { dgUserNote.EditItemIndex = e.Item.ItemIndex; } but when i click edit first time it will not work; second time only it will work likewise when i'm clicking cancel button first time it will not work,second time it is going to upadtecommand . cancel i written like this; void dgUserNote_CancelCommand(object source, DataGridCommandEventArgs e) { dgUserNote.EditItemIndex = -1; } and Update i written like this; SqlCommand SqlCom; try { if (ConGlobal.State == ConnectionState.Closed) ConGlobal.Open(); SqlCom = new SqlCommand("SpInsertUserNote", ConGlobal); SqlCom.Parameters.Add("@IorU", SqlDbType.VarChar).SqlValue = "U"; SqlCom.Parameters.Add("@Title", SqlDbType.VarChar).SqlValue = e.Item.Cells[2].Text; SqlCom.Parameters.Add("@Description", SqlDbType.VarChar).SqlValue = e.Item.Cells[3].Text; SqlCom.Parameters.Add("@Date", SqlDbType.VarChar).SqlValue = e.Item.Cells[4].Text; SqlCom.Parameters.Add("@UserName", SqlDbType.VarChar).SqlValue = mdlNewClass.gStrUserName; SqlCom.CommandType = CommandType.StoredProcedure; SqlCom.ExecuteNonQuery(); SqlCom = null; Response.Write("Record Updated Successfully..."); BindData(); dgUserNote.EditItemIndex = -1; } pls help me in this issue

    R 1 Reply Last reply
    0
    • P princy10

      Hi, I'm using .net 2008.i've a datagrid named 'dgUserNote'. I add edit,cancel,upadte and delete like this; and in coding part i written like; void dgUserNote_EditCommand(object source, DataGridCommandEventArgs e) { dgUserNote.EditItemIndex = e.Item.ItemIndex; } but when i click edit first time it will not work; second time only it will work likewise when i'm clicking cancel button first time it will not work,second time it is going to upadtecommand . cancel i written like this; void dgUserNote_CancelCommand(object source, DataGridCommandEventArgs e) { dgUserNote.EditItemIndex = -1; } and Update i written like this; SqlCommand SqlCom; try { if (ConGlobal.State == ConnectionState.Closed) ConGlobal.Open(); SqlCom = new SqlCommand("SpInsertUserNote", ConGlobal); SqlCom.Parameters.Add("@IorU", SqlDbType.VarChar).SqlValue = "U"; SqlCom.Parameters.Add("@Title", SqlDbType.VarChar).SqlValue = e.Item.Cells[2].Text; SqlCom.Parameters.Add("@Description", SqlDbType.VarChar).SqlValue = e.Item.Cells[3].Text; SqlCom.Parameters.Add("@Date", SqlDbType.VarChar).SqlValue = e.Item.Cells[4].Text; SqlCom.Parameters.Add("@UserName", SqlDbType.VarChar).SqlValue = mdlNewClass.gStrUserName; SqlCom.CommandType = CommandType.StoredProcedure; SqlCom.ExecuteNonQuery(); SqlCom = null; Response.Write("Record Updated Successfully..."); BindData(); dgUserNote.EditItemIndex = -1; } pls help me in this issue

      R Offline
      R Offline
      Ryomin
      wrote on last edited by
      #2

      Maybe i'm missing something but my guess is you should rebind your DataGrid after the event fires. Example with your Edit Handler

      protected void dgUserNote_EditCommand(object source, DataGridCommandEventArgs e)
      {
      dgUserNote.EditItemIndex = e.Item.ItemIndex;
      BindData();
      }

      If you Re-Bind your DataGrid after all your commands are issued it should work fine for you. Best of luck,

      Cheers Disgyza Programmer Analyst

      P 1 Reply Last reply
      0
      • R Ryomin

        Maybe i'm missing something but my guess is you should rebind your DataGrid after the event fires. Example with your Edit Handler

        protected void dgUserNote_EditCommand(object source, DataGridCommandEventArgs e)
        {
        dgUserNote.EditItemIndex = e.Item.ItemIndex;
        BindData();
        }

        If you Re-Bind your DataGrid after all your commands are issued it should work fine for you. Best of luck,

        Cheers Disgyza Programmer Analyst

        P Offline
        P Offline
        princy10
        wrote on last edited by
        #3

        Thanks for the solution. can u pls help me to find solution regarding with my Datagrid. I'm new to c#. in my coding i'm using control DataGrid named dgUserNote. in its update command , i'm not getting the values in the cells when i take e.Item.Cells[2].Text it shows like; e.Item.Cells[2].Text="" the code is as follows; in designing part(asp) i add the Column as follows; UpdateText="Update"> in coding (c#) i wrote like this; void dgUserNote_UpdateCommand(object source, DataGridCommandEventArgs e) { SqlCommand SqlCom; if (ConGlobal.State == ConnectionState.Closed) ConGlobal.Open(); SqlCom = new SqlCommand("SpInsertUserNote", ConGlobal); SqlCom.Parameters.Add("@IorU", SqlDbType.VarChar).SqlValue = "U"; SqlCom.Parameters.Add("@Title", SqlDbType.VarChar).SqlValue = e.Item.Cells[2].Text; SqlCom.Parameters.Add("@Description", SqlDbType.VarChar).SqlValue = e.Item.Cells[3].Text; SqlCom.Parameters.Add("@Date", SqlDbType.VarChar).SqlValue = e.Item.Cells[4].Text; SqlCom.Parameters.Add("@UserName", SqlDbType.VarChar).SqlValue = mdlNewClass.gStrUserName; SqlCom.CommandType = CommandType.StoredProcedure; SqlCom.ExecuteNonQuery(); SqlCom = null; Response.Write("Record Updated Successfully..."); BindData(); dgUserNote.EditItemIndex = -1; dgUserNote.DataBind(); } pls help me to solve this problem Thanks&Regards Princy

        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