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

Error argument out of range in GridBoundColumn, Telerik 2014

5 Answers 67 Views
Grid
This is a migrated thread and some comments may be shown as answers.
fatma
Top achievements
Rank 1
fatma asked on 29 Jan 2015, 05:02 PM
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

5 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 29 Jan 2015, 07:21 PM
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
0
fatma
Top achievements
Rank 1
answered on 30 Jan 2015, 05:10 PM
Hello,

My Telerik version is 2014.1.403.45
The problem is not resolved

Please help 
0
Jayesh Goyani
Top achievements
Rank 2
answered on 01 Feb 2015, 12:06 PM
Hello,

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

Thanks,
Jayesh Goyani
0
fatma
Top achievements
Rank 1
answered on 03 Feb 2015, 03:30 PM
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?


0
fatma
Top achievements
Rank 1
answered on 03 Feb 2015, 05:24 PM
Finally, I resolved  the problem.
The TextBoxControl.ID should be "TB_OvercostEuros"

editor.TextBoxControl.ID = "TB_OvercostEuros"

:)
Tags
Grid
Asked by
fatma
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
fatma
Top achievements
Rank 1
Share this question
or