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:
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:
Best regards.
Waleed
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"]); |
"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