Click here to Skip to main content
15,891,758 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
i have dynamic grid view for edit multiple product store in database. now i want to edit that product so using edit command of gridview but there is no record set in textbox inside gridview.
here is code for that :-

C#
protected void GrdOrder_EditCommand(object source, DataGridCommandEventArgs e)
    {
        try
        {
            int OID = Convert.ToInt32(GrdOrder.DataKeys[e.Item.ItemIndex]);
            DatabaseHelper db = new DatabaseHelper();
            

                int rowIndex = 0;

                db.GetProductByOrderID(Convert.ToInt32(OID));
                

                if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
                {
                    for (int i = 1; i <= ds.Tables[0].Rows.Count; i++)
                    {
                        TextBox box1 = (TextBox)GrdProduct.Rows[rowIndex].Cells[1].FindControl("txtitemname");
                        TextBox box2 = (TextBox)GrdProduct.Rows[rowIndex].Cells[1].FindControl("txtqty");
                        TextBox box3 = (TextBox)GrdProduct.Rows[rowIndex].Cells[1].FindControl("txtprice");

                        
                        box1.Text = ds.Tables[0].Rows[0]["ProductName"].ToString();
                        box2.Text = ds.Tables[0].Rows[0]["Quantity"].ToString();
                        box3.Text = ds.Tables[0].Rows[0]["Price"].ToString();

                        rowIndex++;
                    }
                }
            }
        }
        catch (Exception ex)
        {
            lblerror.Visible = true;
            lblerror.InnerText = ex.Message.ToString();
        }
    }


my ds.Tables[0] found row 2 .when i try to bind in gridview its not bind.
any one other view to bind it dynamically...
whne i try to bound it give error like that
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
Posted
Updated 23-Aug-12 2:25am
v2
Comments
pradiprenushe 23-Aug-12 8:13am    
Dont need toset anything
Just add these two lines in editcommand event. Remove all other lines
GrdOrder.EditIndex = e.NewEditIndex
GrdOrder.DataBind()
Yatin chauhan 23-Aug-12 8:24am    
there is no any editIndex method or property for GrdOrder. i create grdorder dynamically.
pradiprenushe 23-Aug-12 8:46am    
When grid edit command called its editIndex property automatically get set.
Yatin chauhan 23-Aug-12 9:05am    
but i have two grid when i click on my GrdOrder_EditCommand at that time i want to bind GrdOrder grid which i created dynamically...!!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900