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. problem in editing in gridview

problem in editing in gridview

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

    hi i have code at grid view editing have proble at update time protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { //fetch datakey/primarykey for identifyning the row string materialrecipt_no = Convert.ToString(GridView1.DataKeys[e.RowIndex].Value); TextBox materialrecip_date = (TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[1]; TextBox pqty = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[1]); TextBox enterby = ((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[1]); TextBox ptype = ((TextBox)GridView1.Rows[e.RowIndex].Cells[5].Controls[1]); TextBox remark = ((TextBox)GridView1.Rows[e.RowIndex].Cells[6].Controls[1]); SqlCommand com = new SqlCommand("update material_incoming set materialrecip_date='" + materialrecip_date.Text + "',pqty='" + pqty.Text + "',enterby='" + enterby.Text + "',ptype='" + ptype.Text + "',remark='" + remark.Text + "' where materialrecipt_no=" + materialrecipt_no + "", conn); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); GridView1.EditIndex = -1; //to go back to the previous position // fetch and rebind the data. BindGrid(); } but it gives an error error is Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

    L K 2 Replies Last reply
    0
    • P prateekfgiet

      hi i have code at grid view editing have proble at update time protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { //fetch datakey/primarykey for identifyning the row string materialrecipt_no = Convert.ToString(GridView1.DataKeys[e.RowIndex].Value); TextBox materialrecip_date = (TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[1]; TextBox pqty = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[1]); TextBox enterby = ((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[1]); TextBox ptype = ((TextBox)GridView1.Rows[e.RowIndex].Cells[5].Controls[1]); TextBox remark = ((TextBox)GridView1.Rows[e.RowIndex].Cells[6].Controls[1]); SqlCommand com = new SqlCommand("update material_incoming set materialrecip_date='" + materialrecip_date.Text + "',pqty='" + pqty.Text + "',enterby='" + enterby.Text + "',ptype='" + ptype.Text + "',remark='" + remark.Text + "' where materialrecipt_no=" + materialrecipt_no + "", conn); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); GridView1.EditIndex = -1; //to go back to the previous position // fetch and rebind the data. BindGrid(); } but it gives an error error is Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Set a break point in your code, Find which line of code throws the error check the following e.RowIndex - if it is a negative value, it may throw an error at GridView1.Rows[e.RowIndex] Cells collection - check whether indexs of the grid cells are within the range.

      1 Reply Last reply
      0
      • P prateekfgiet

        hi i have code at grid view editing have proble at update time protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { //fetch datakey/primarykey for identifyning the row string materialrecipt_no = Convert.ToString(GridView1.DataKeys[e.RowIndex].Value); TextBox materialrecip_date = (TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[1]; TextBox pqty = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[1]); TextBox enterby = ((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[1]); TextBox ptype = ((TextBox)GridView1.Rows[e.RowIndex].Cells[5].Controls[1]); TextBox remark = ((TextBox)GridView1.Rows[e.RowIndex].Cells[6].Controls[1]); SqlCommand com = new SqlCommand("update material_incoming set materialrecip_date='" + materialrecip_date.Text + "',pqty='" + pqty.Text + "',enterby='" + enterby.Text + "',ptype='" + ptype.Text + "',remark='" + remark.Text + "' where materialrecipt_no=" + materialrecipt_no + "", conn); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); GridView1.EditIndex = -1; //to go back to the previous position // fetch and rebind the data. BindGrid(); } but it gives an error error is Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

        K Offline
        K Offline
        Kaushal Arora
        wrote on last edited by
        #3

        Hi, What i think the problem is in the place where you refer to your control using Cells[index].Controls[1] and there would have been only one control and that too at position [0] not [1]. So try using the code like this as you do know the name of the control which you want to fetch using the code for updation purpose. protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { //fetch datakey/primarykey for identifyning the row string materialrecipt_no = Convert.ToString(GridView1.DataKeys[e.RowIndex].Value); TextBox materialrecip_date = (TextBox)GridView1.Rows[e.RowIndex].FindControl("ControlName"); TextBox pqty = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("ControlName")); TextBox enterby = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("ControlName")); TextBox ptype = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("ControlName")); TextBox remark = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("ControlName")); SqlCommand com = new SqlCommand("update material_incoming set materialrecip_date='" + materialrecip_date.Text + "',pqty='" + pqty.Text + "',enterby='" + enterby.Text + "',ptype='" + ptype.Text + "',remark='" + remark.Text + "' where materialrecipt_no=" + materialrecipt_no + "", conn); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); GridView1.EditIndex = -1; //to go back to the previous position // fetch and rebind the data. BindGrid(); } Please mark as answer if problem gets resolved. Regards, Kaushal Arora

        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