This is a migrated thread and some comments may be shown as answers.

Edit Using WebuserControl

2 Answers 88 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Waleed Seada
Top achievements
Rank 2
Waleed Seada asked on 04 Jun 2008, 07:48 AM
Dear all,

I follow the example that uses a WebUserControl as editform for Rad grid.

I got as Exception when pressing the update button at that line where I access the OwnertableView:
DataRow[] dr = Products.Select("ProductID = " + editable.OwnerTableView.DataKeyValues[editable.ItemIndex]["ProductID"]); 
The Exception says : ArrgumentOutOfRangeExeption 
"Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index"

Here is the full EventHandler code:
protected void Grid2_UpdateCommand(object source,GridCommandEventArgs e)  
        {  
            GridEditableItem editable = e.Item as GridEditableItem;  
              
            UserControl uc = (UserControl) e.Item.FindControl(GridEditFormItem.EditFormUserControlID);  
            DataRow[] dr = Products.Select("ProductID = " + editable.OwnerTableView.DataKeyValues[editable.ItemIndex]["ProductID"]);  
              
            // Can not find the ID to update ....  
            if(dr.Length != 1)  
            {  
                Grid2.Controls.Add(new LiteralControl("Can not find Item to update!!"));  
                e.Canceled = true;  
                return;  
            }  
            try 
            {  
                Hashtable ht = CollectFormData(e);  
                ht["ProductID"] = (int)editable.OwnerTableView.DataKeyValues[editable.ItemIndex]["ProductID"];  
 
                SqlDataAdapter da = new SqlDataAdapter(productSelect, ConnObject);  
                  
                SqlCommandBuilder cb = new SqlCommandBuilder(da);  
              
                dr[0].BeginEdit();  
                foreach (DictionaryEntry entry in ht)  
                {  
                    dr[0][(string)entry.Key] = entry.Value;  
                }  
                dr[0].EndEdit();  
 
                ConnObject.Open();  
                da.Update(dataSet, "Products");  
            }  
            catch(Exception ex)  
            {  
                Grid2.Controls.Add(new LiteralControl("Can not update record !!"));  
                e.Canceled = true;  
            }  
            finally 
            {  
                ConnObject.Close();  
            }  
        } 

Best regards.
Waleed

2 Answers, 1 is accepted

Sort by
0
Prangadj
Top achievements
Rank 1
answered on 06 Jun 2008, 10:43 AM
Waleed, I would check with debugging whether the GridEditableItem (called editable) is the proper row which has to be updated. Also see if ProductID is set as primary key in DataKeyNames and the index of the edited item exists.

Prangadj
0
Waleed Seada
Top achievements
Rank 2
answered on 08 Jun 2008, 10:49 AM
Hello Prangadj,

What do you mean by "is the proper row which has to be updated" !!

Can you elaborate more ...

Best regards,
Waleed
Tags
Grid
Asked by
Waleed Seada
Top achievements
Rank 2
Answers by
Prangadj
Top achievements
Rank 1
Waleed Seada
Top achievements
Rank 2
Share this question
or