Error argument out of range in GridBoundColumn, Telerik 2014

6 posts, 0 answers
  1. fatma
    fatma avatar
    10 posts
    Member since:
    Apr 2014

    Posted 29 Jan 2015 Link to this post

    Hello,
    I upgraded to new Telerik version 2014_1_403 from 2011_3_1305 and compatibility issues started...

    ASP :
                <telerik:RadGrid runat="server" DataSourceID="dsStandardProduct" ID="uiChoicesGrid"
                    Width="900" >
                    <MasterTableView AutoGenerateColumns="false" AllowAutomaticInserts="true" AllowAutomaticUpdates="true"
                        AllowAutomaticDeletes="true" CommandItemDisplay="Top"  InsertItemDisplay="Top"
                        DataKeyNames="ProductTypeID, ValueRangeID" EditMode="InPlace">
                        <Columns>
                               <telerik:GridCheckBoxColumn SortExpression="IsStandard" HeaderText="Standard" HeaderButtonType="TextButton" DataField="IsStandard" UniqueName="IsStandard">
                            </telerik:GridCheckBoxColumn>
                            <telerik:GridBoundColumn SortExpression="OvercostEuros" HeaderText="Overcost (Euros)"
                                HeaderButtonType="TextButton" DataField="OvercostEuros" UniqueName="OvercostEuros">
                            </telerik:GridBoundColumn>
                        </Columns>
                    </MasterTableView>
                </telerik:RadGrid>

    VB : 
        Private Sub uiChoicesGrid_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles uiChoicesGrid.ItemDataBound
            If TypeOf e.Item Is GridDataInsertItem Then
                Dim item As GridDataInsertItem = e.Item
                Dim chk As CheckBox = item("IsStandard").Controls(0)
                Dim txt As TextBox = item("OverCostEuros").Controls(0)
                                     logic continues...

    But the above line of code "Dim txt As TextBox = item("OverCostEuros").Controls(0)" generates an Argument Out Of Range Exception 

    Please suggest. 
    Thanks

  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 29 Jan 2015 in reply to fatma Link to this post

    Hello,

    I have tried with your code but I am not able to reproduce the error. For telerik version I have attached screenshot.

    <telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource" ShowFooter="true" OnItemDataBound="RadGrid1_ItemDataBound"
               OnPreRender="RadGrid1_PreRender" OnItemCreated="RadGrid1_ItemCreated" AllowPaging="true" AllowFilteringByColumn="true"
               AllowMultiRowSelection="true" OnItemCommand="RadGrid1_ItemCommand" AllowSorting="true">
               <MasterTableView AutoGenerateColumns="False" DataKeyNames="Id" ClientDataKeyNames="Id" CommandItemDisplay="Top" EditMode="InPlace">
                   <Columns>
                       <telerik:GridClientSelectColumn></telerik:GridClientSelectColumn>
                       <telerik:GridBoundColumn DataField="Id" HeaderText="Id" UniqueName="Id">
                       </telerik:GridBoundColumn>
                       <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name">
                       </telerik:GridBoundColumn>
                       <telerik:GridEditCommandColumn></telerik:GridEditCommandColumn>
                       <telerik:GridBoundColumn SortExpression="OvercostEuros" HeaderText="Overcost"
                           HeaderButtonType="TextButton" DataField="Name" UniqueName="OvercostEuros">
                       </telerik:GridBoundColumn>
                   </Columns>
               </MasterTableView>
               <ClientSettings>
                   <Selecting AllowRowSelect="true" />
               </ClientSettings>
           </telerik:RadGrid>
    protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
       {
           dynamic data = new[] {
                   new { ID = 1, Name ="Name1"},
                   new { ID = 2, Name ="Name2"}
               };
           RadGrid1.DataSource = data;
       }
     
       protected void RadGrid1_PreRender(object sender, EventArgs e)
       {
     
       }
     
       protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
       {
           if (e.Item is GridDataInsertItem)
           {
               GridDataInsertItem item = e.Item as GridDataInsertItem;
               (item["OvercostEuros"].Controls[0] as TextBox).Text = "jayesh";
           }
     
               
       }
     
       protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
       {
         
       }
     
       protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
       {
          
       }


    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. fatma
    fatma avatar
    10 posts
    Member since:
    Apr 2014

    Posted 30 Jan 2015 in reply to Jayesh Goyani Link to this post

    Hello,

    My Telerik version is 2014.1.403.45
    The problem is not resolved

    Please help 
  5. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 01 Feb 2015 in reply to fatma Link to this post

    Hello,

    Could you please sample application, in which this issue is exists and share with us? 

    Thanks,
    Jayesh Goyani
  6. fatma
    fatma avatar
    10 posts
    Member since:
    Apr 2014

    Posted 03 Feb 2015 in reply to Jayesh Goyani Link to this post

    Hello,
    I found the source of the error,
    In my code, i have a range validator to a GridBoundColumn in ItemCreated.
    when i set the value of TextBoxControl.ID in the Sub Item created, the line of code  "Dim txt As TextBox = item("OverCostEuros").Controls(0)" generates an Argument Out Of Range Exception 

    the code is :
    <telerik:RadGrid runat="server" DataSourceID="dsStandardProduct" ID="uiChoicesGrid"
                    Width="900" >
                    <MasterTableView AutoGenerateColumns="false" AllowAutomaticInserts="true" AllowAutomaticUpdates="true"
                        AllowAutomaticDeletes="true" CommandItemDisplay="Top"  InsertItemDisplay="Top"
                        DataKeyNames="ProductTypeID, ValueRangeID" EditMode="InPlace">
                        <Columns>
                               <telerik:GridCheckBoxColumn SortExpression="IsStandard" HeaderText="Standard" HeaderButtonType="TextButton" DataField="IsStandard" UniqueName="IsStandard">
                            </telerik:GridCheckBoxColumn>
                            <telerik:GridBoundColumn SortExpression="OvercostEuros" HeaderText="Overcost (Euros)"
                                HeaderButtonType="TextButton" DataField="OvercostEuros" UniqueName="OvercostEuros">
                            </telerik:GridBoundColumn>
                        </Columns>
                    </MasterTableView>
                </telerik:RadGrid>

    VB:

    Private Sub uiChoicesGrid_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles uiChoicesGrid.ItemCreated
            If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then
                Dim item As GridEditableItem = CType(e.Item, GridEditableItem)
                Dim editor As GridTextBoxColumnEditor = CType(item.EditManager.GetColumnEditor("OvercostEuros"), GridTextBoxColumnEditor)
                Dim cell As TableCell = CType(editor.TextBoxControl.Parent, TableCell)
                Dim validator As RangeValidator = New RangeValidator
                editor.TextBoxControl.ID = "ID_for_validation"
                validator.Type = ValidationDataType.Currency
                validator.Display = ValidatorDisplay.Dynamic
                validator.MinimumValue = 0
                validator.MaximumValue = 99999999
                validator.ControlToValidate = editor.TextBoxControl.ID
                validator.ErrorMessage = "*"
                cell.Controls.Add(validator)
        End If
    End Sub

     Private Sub uiChoicesGrid_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles uiChoicesGrid.ItemDataBound
            If TypeOf e.Item Is GridDataInsertItem Then
                Dim item As GridDataInsertItem = e.Item
                Dim chk As CheckBox = item("IsStandard").Controls(0)
                Dim txt As TextBox = item("OverCostEuros").Controls(0)
                chk.Attributes.Add("onclick", "OnStandardChoiceClick(this,{OverCostID : '" & txt.ClientID & "' })")
                        ..............

    Where is the matter please?


  7. fatma
    fatma avatar
    10 posts
    Member since:
    Apr 2014

    Posted 03 Feb 2015 in reply to fatma Link to this post

    Finally, I resolved  the problem.
    The TextBoxControl.ID should be "TB_OvercostEuros"

    editor.TextBoxControl.ID = "TB_OvercostEuros"

    :)
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017