Edit Using WebuserControl

3 posts, 0 answers
  1. Waleed Seada
    Waleed Seada avatar
    241 posts
    Member since:
    May 2006

    Posted 04 Jun 2008 Link to this post

    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. Prangadj
    Prangadj avatar
    174 posts
    Member since:
    Jan 2008

    Posted 06 Jun 2008 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Waleed Seada
    Waleed Seada avatar
    241 posts
    Member since:
    May 2006

    Posted 08 Jun 2008 Link to this post

    Hello Prangadj,

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

    Can you elaborate more ...

    Best regards,
    Waleed
Back to Top