This is a migrated thread and some comments may be shown as answers.
Out of Index error on edit
1 Answer 17 Views
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 29 Dec 2011, 09:21 PM
I'm getting the following error when I click on the edit link in my grid.  Any help would be appreciated.

Specified argument was out of the range of valid values.
Parameter name: index


Aspx:
<telerik:RadGrid ID="grdWebForm" CssClass="infoDisplayGrid" runat="server" Skin="Office2007"
                  AllowPaging="true" OnPageIndexChanged="grdWebForm_PageIndexChanged" 
                  OnPageSizeChanged="grdWebForm_OnPageSizeChanged" PageSize="25"
                  AllowSorting="true" OnSortCommand="grdWebForm_SortCommand" OnNeedDataSource="grdWebForm_NeedDataSource"  OnItemDataBound="grdWebForm_ItemDataBound" 
                  AutoGenerateColumns="false" 
                  OnUpdateCommand="grdWebForm_UpdateCommand" OnDeleteCommand="grdWebForm_DeleteCommand" OnInsertCommand="grdWeForm_InsertCommand" OnPreRender="grdWebForm_PreRender">        
     <PagerStyle AlwaysVisible="true" />
     <MasterTableView DataKeyNames="RTFieldQCId" EditMode="InPlace" CommandItemDisplay="Top">
         <Columns>
             <telerik:GridDropDownColumn UniqueName="FullName" HeaderText="Tech Name" DataField="TechId" ListValueField="TechId" ListTextField="FullName" DropDownControlType="DropDownList"></telerik:GridDropDownColumn>                      
             <telerik:GridBoundColumn  UniqueName="LegacyMeterSerial" SortExpression="LegacyMeterSerial" HeaderText="Legacy Meter #" DataField="LegacyMeterSerial"></telerik:GridBoundColumn>
               
             <telerik:GridDateTimeColumn UniqueName="QCDate" PickerType="DatePicker" HeaderText="Date" DataField="QCDate" DataFormatString="{0:MM/dd/yyyy}"  EditDataFormatString="MMMM dd">
                 <ItemStyle Width="120px" />
             </telerik:GridDateTimeColumn>
             <telerik:GridNumericColumn UniqueName="Score" SortExpression="Score" HeaderText="Score" DataField="Score" ColumnEditorID="GridNumericColumnEditor1"></telerik:GridNumericColumn>
             <telerik:GridNumericColumn UniqueName="MaxScore" SortExpression="MaxScore" HeaderText="Max Score" DataField="MaxScore" ColumnEditorID="GridNumericColumnEditor1"></telerik:GridNumericColumn>
             <telerik:GridBoundColumn  UniqueName="Action" SortExpression="Action" HeaderText="Action" DataField="Action">
             </telerik:GridBoundColumn>                    
             <telerik:GridEditCommandColumn UpdateText="Update" UniqueName="EditCommandColumn" CancelText="Cancel" EditText="Edit">
                 <HeaderStyle Width="85px"></HeaderStyle>
             </telerik:GridEditCommandColumn>        
             <telerik:GridButtonColumn UniqueName="DeleteColumn" Text="Delete" CommandName="Delete"  /> 
         </Columns>
           
     </MasterTableView>
</telerik:RadGrid>          
     <telerik:GridNumericColumnEditor ID="GridNumericColumnEditor1" runat="server">
     <NumericTextBox MaxLength="4" EmptyMessage="Ext." runat="server">
         <NumberFormat GroupSeparator="," />
     </NumericTextBox>
 </telerik:GridNumericColumnEditor>

CodeBehind:
protected void grdWebForm_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
 {
     //if (rt_table != string.Empty)
     //{
         grdWebForm.DataSource = GetWebFormData();
     //}
 }
 protected void grdWebForm_ItemDataBound(object sender, GridItemEventArgs e)
 {
     if (e.Item is GridEditableItem && e.Item.IsInEditMode)
     {
         GridEditableItem editedItem = e.Item as GridEditableItem;
         GridEditManager editMan = editedItem.EditManager;
         GridDropDownColumnEditor editor = editMan.GetColumnEditor("FullName") as GridDropDownColumnEditor;
         List<TechInfo> techList = BuildTechSelectLists(false);
         editor.DataSource = techList; // BuildTechSelectLists(false);
         editor.DataTextField = "FullName";
         editor.DataValueField = "UserId";
         editor.DataBind();
     }
     if (e.Item is GridDataItem)
     {
         GridDataItem item = (GridDataItem)e.Item;
         DataRowView row = (DataRowView)e.Item.DataItem;
         item["FullName"].Text = row["FullName"].ToString();
     }
 }
public DataTable GetWebFormData()
 {
     SqlConnection connection = new SqlConnection(
     ConfigurationManager.ConnectionStrings["ProFieldMeter"].ConnectionString);
     DataTable dt = new DataTable();
     string strquery = "Select qc.RTFieldQCID,qc.TechId,qc.LegacyMeterSerial,qc.QCDate,qc.Score,qc.MaxScore,qc.Attachment,qc.Action, u.Lastname + ', ' + u.FirstName as FullName FROM RTFieldQC qc left join ProFieldCore.dbo.ProfieldUser u on qc.TechId = u.UserId";
     SqlDataAdapter adapter = new SqlDataAdapter(strquery, connection);
     adapter.Fill(dt);
     return dt;
 }

1 Answer, 1 is accepted

Sort by
0
Antonio Stoilkov
Telerik team
answered on 30 Dec 2011, 03:04 PM
Hi Michael,

You could resolve your issue by adding additional condition in the ItemCreated event checking if the e.Item is not in edit mode. The corrected code is below.

if (e.Item is GridDataItem && !e.Item.IsInEditMode)
{
    GridDataItem item = (GridDataItem)e.Item;
    DataRowView row = (DataRowView)e.Item.DataItem;
    item["FullName"].Text = row["FullName"].ToString();
}

Greetings,
Antonio Stoilkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Antonio Stoilkov
Telerik team
Share this question
or