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

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

2 Answers 503 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cecilie Nordbø
Top achievements
Rank 1
Cecilie Nordbø asked on 14 Dec 2010, 12:35 PM
Hi.
I got this error when i tried to edit the row in a hierarchical grid. I have one nested grid where i changed the UnitPrice value in ItemDataBound event. I need do divide the value to get the right currency. (If i do not, than i can do edit action in the nested grid without getting the error.) I have found in the forum other thread with the same error but it does not solve my case. The code i use is:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
       {
           if (e.Item is GridDataItem)
           {
               LoadTransAndDetailValues(e);
           }           
       }
 
private void LoadTransAndDetailValues(GridItemEventArgs e)
       {
           var item = e.Item as GridDataItem;
           if (e.Item.DataItem is Detail)
           {               
               var detail = e.Item.DataItem as Detail;                           
               double? unitPrice = detail.UnitPrice;
               item["UnitPrice"].Text = (unitPrice.HasValue && unitPrice.Value != 0) ?    (unitPrice.Value / 100.00).ToString() : "";
           }          
       }
<telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" GridLines="None" ShowGroupPanel="True" ShowStatusBar="True"
        Culture="Norwegian, Bokmål (Norway)" AutoGenerateColumns="False" Width="620px" onitemcommand="RadGrid1_ItemCommand" onitemdatabound="RadGrid1_ItemDataBound" AllowAutomaticUpdates="True"
        onneeddatasource="RadGrid1_NeedDataSource" onupdatecommand="RadGrid1_UpdateCommand">
    <MasterTableView AutoGenerateColumns="False" DataKeyNames="TransId" EditMode="InPlace">
    <RowIndicatorColumn><HeaderStyle Width="20px"></HeaderStyle></RowIndicatorColumn>
        <DetailTables>
            <telerik:GridTableView runat="server" AllowPaging="False" DataKeyNames="DetailId" AllowFilteringByColumn="false" EditMode="InPlace" DataSourceID="DetailDataSource">
            <ParentTableRelation><telerik:GridRelationFields DetailKeyField="TransId" MasterKeyField="TransId"/></ParentTableRelation>
            <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
            <Columns>                   
                <telerik:GridBoundColumn  UniqueName="JourneyTime" HeaderText="Tur" DataField="JourneyTime" ReadOnly="true" SortExpression="JourneyTime" AllowFiltering="true" ShowFilterIcon="false" AutoPostBackOnFilter="true" >
                <HeaderStyle Width="30px"></HeaderStyle><ItemStyle HorizontalAlign="Right" /></telerik:GridBoundColumn>            
                <telerik:GridBoundColumn  UniqueName="RouteName" HeaderText="Rute" DataField="RouteName" ReadOnly="true" SortExpression="RouteName" AllowFiltering="true" ShowFilterIcon="false" AutoPostBackOnFilter="true" >
                <HeaderStyle Width="50px"></HeaderStyle></telerik:GridBoundColumn>            
                <telerik:GridNumericColumn  UniqueName="TariffNr" DataType="System.Int32" HeaderText="Billettkode" DataField="TariffNr" SortExpression="TariffNr">
                <HeaderStyle Width="30px"></HeaderStyle><ItemStyle HorizontalAlign="Right"/></telerik:GridNumericColumn>                            
                <telerik:GridNumericColumn  UniqueName="DetailCount" DataType="System.Int32" HeaderText="Antall" DataField="DetailCount" SortExpression="DetailCount">
                <HeaderStyle Width="30px"></HeaderStyle><ItemStyle HorizontalAlign="Right"/></telerik:GridNumericColumn>                                            
                <telerik:GridNumericColumn  UniqueName="UnitPrice" HeaderText="Pris"  DataField="UnitPrice" DataType="System.Double" SortExpression="UnitPrice">
                <HeaderStyle Width="40px"></HeaderStyle><ItemStyle HorizontalAlign="Right"/></telerik:GridNumericColumn>                             
                <telerik:GridEditCommandColumn CancelText="Avbryt" EditText="Endre" InsertText="Sett inn" UpdateText="Oppdater" UniqueName="EditColumn"><HeaderStyle Width="105px"></HeaderStyle><ItemStyle HorizontalAlign="Right" /></telerik:GridEditCommandColumn>          
            </Columns>
            <EditFormSettings>
                <EditColumn UniqueName="EditCommandColumn1"></EditColumn>
            </EditFormSettings>
            </telerik:GridTableView>
        </DetailTables>
    <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
    <ExpandCollapseColumn Visible="True"></ExpandCollapseColumn>
    <Columns>
            <telerik:GridBoundColumn FilterControlWidth="95%" DataField="TransDate" DataType="System.DateTime" HeaderText="Dato" ReadOnly="True" SortExpression="TransDate" UniqueName="TransDate" ShowFilterIcon="false" AutoPostBackOnFilter="true">
        <HeaderStyle Width="140px"></HeaderStyle></telerik:GridBoundColumn
        <telerik:GridBoundColumn FilterControlWidth="95%" DataField="UserNr" DataType="System.Int32" HeaderText="Brukernr." ReadOnly="True" SortExpression="UserNr" UniqueName="UserNr" ShowFilterIcon="false" AutoPostBackOnFilter="true" CurrentFilterFunction="StartsWith">
        <HeaderStyle Width="100px"></HeaderStyle><ItemStyle HorizontalAlign="Right"/></telerik:GridBoundColumn>       
        <telerik:GridBoundColumn FilterControlWidth="95%" DataField="TicketNr" DataType="System.Int32" HeaderText="Billettnr." ReadOnly="True" SortExpression="TicketNr" UniqueName="TicketNr" ShowFilterIcon="false" AutoPostBackOnFilter="true" CurrentFilterFunction="StartsWith">
        <HeaderStyle Width="100px"></HeaderStyle><ItemStyle HorizontalAlign="Right"/></telerik:GridBoundColumn>                                  
        <telerik:GridBoundColumn FilterControlWidth="95%" DataField="AnnulComment" HeaderText="Annullerings kommentar" SortExpression="AnnulComment" UniqueName="AnnulComment" ShowFilterIcon="false" AutoPostBackOnFilter="true" CurrentFilterFunction="StartsWith">
        <HeaderStyle Width="200px"></HeaderStyle></telerik:GridBoundColumn>                 
        <telerik:GridEditCommandColumn CancelText="Avbryt" EditText="Endre" InsertText="Sett inn" UpdateText="Oppdater" UniqueName="EditColumn">
        <HeaderStyle Width="105px"></HeaderStyle><ItemStyle HorizontalAlign="Right" /></telerik:GridEditCommandColumn>     
        <telerik:GridButtonColumn CommandName="Annul" Text="Annuller" UniqueName="AnnulColumn"><HeaderStyle Width="50px"></HeaderStyle></telerik:GridButtonColumn>            
    </Columns>
    <NoRecordsTemplate><div>Det er ingen elementer å vise</div></NoRecordsTemplate>       
    </MasterTableView>
    <ClientSettings EnableRowHoverStyle="true">                       
        <Resizing AllowColumnResize="true"/>
        <ClientEvents OnRowDblClick="RowDblClick" />
        <Selecting AllowRowSelect="true"/>
    </ClientSettings>
    <SortingSettings EnableSkinSortStyles="False" SortedAscToolTip="Sortert stigende" SortedDescToolTip="Sortet synkende" SortToolTip="Klikk her for å sortere" />           
    </telerik:RadGrid>
    
   <asp:LinqDataSource ID="DetailDataSource" runat="server" ContextTypeName="MtbsLinq.MtbsDataContext"
        TableName="Details" Where="TransId == @TransId" EnableUpdate="True">
        <WhereParameters>
            <asp:ControlParameter ControlID="RadGrid1" Name="TransId" PropertyName="SelectedValue" Type="Int32" DefaultValue="0"/>
        </WhereParameters>
    </asp:LinqDataSource>       
</asp:Content>

2 Answers, 1 is accepted

Sort by
0
Cecilie Nordbø
Top achievements
Rank 1
answered on 16 Dec 2010, 09:11 AM
I really need to find out of this error. Anyone??
0
Accepted
Martin
Telerik team
answered on 17 Dec 2010, 06:16 PM
Hello Cecilie Nordbø,

Note that when an item is in edit mode it renders editor controls instead of text for the its columns. Therefore, you should set your custom value to the relevant column editor. Attached to this message is a small sample that demonstrates how to achieve the desired functionality. Please review it and let me know whether further assistance is needed.

Kind regards,
Martin
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Cecilie Nordbø
Top achievements
Rank 1
Answers by
Cecilie Nordbø
Top achievements
Rank 1
Martin
Telerik team
Share this question
or