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

Binding dropdownlist with inplace edit mode error

1 Answer 57 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Charlotte
Top achievements
Rank 1
Charlotte asked on 14 Nov 2012, 01:35 PM
Hi,

I am trying to bind a dropdownlist in the itemdataBound event, but when I enter edit mode I am getting the error:
"Specified argument was out of the range of valid values. Parameter name: index"
for the line:
"Dim editor As GridDropDownListColumnEditor = CType(editMan.GetColumnEditor("Band"), GridDropDownListColumnEditor)"

I was referring to this to bind the dropdown: http://www.telerik.com/help/aspnet-ajax/grid-customize-configure-griddropdowncolumn.html

Any ideas why I am getting this error?

My code is below:

RadGrid1_ItemDataBound
Private Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound
        If TypeOf e.Item Is GridDataItem Then
            Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
            Dim row As DataRowView = DirectCast(e.Item.DataItem, DataRowView)
 
            item("Band").Text = row("Band").ToString()
            item("capoptioname").Text = row("capoptioname").ToString()
        End If
 
           If (TypeOf e.Item Is GridEditableItem AndAlso CType(e.Item, GridEditableItem).IsInEditMode) Then
            Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
            Dim editMan As GridEditManager = editedItem.EditManager
            Dim editor As GridDropDownListColumnEditor = CType(editMan.GetColumnEditor("Band"), GridDropDownListColumnEditor)
            Dim ddlBand As DropDownList = editor.DropDownListControl
 
            Dim ProductBus As New Product
            Dim bands As Entities.Product.callbandsDataTable
            bands = ProductBus.GetCallBandsList
            ddlBand.DataSource = bands
            ddlBand.DataTextField = "description"
            ddlBand.DataValueField = "value"
            ddlBand.DataBind()
        End If
End Sub

aspx
<telerik:RadGrid ID="RadGrid1" runat="server" PagerStyle-AlwaysVisible="true" AllowPaging="True" AllowSorting="True" pagesize="25" pagerposition="bottom" GridLines="None"
         Width="99.9%" EnableEmbeddedSkins="False" AllowMultiRowEdit="True" OnSortCommand="RadGrid1_SortCommand" ShowStatusBar="True" Skin="p3"
         OnNeedDataSource="RadGrid1_NeedDataSource" AllowFilteringByColumn="True" AutoGenerateColumns="False" CellSpacing="0" Culture="en-GB"  >
 
<MasterTableView EditMode="inplace" AllowMultiColumnSorting="true" DataKeyNames="id" GridLines="Both" CommandItemDisplay="Top" >
             
<CommandItemSettings ExportToPdfText="Export to PDF" />
        <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True"> </RowIndicatorColumn>
        <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True"> </ExpandCollapseColumn>
         <CommandItemTemplate>
             
        </CommandItemTemplate>
 
        <Columns>
                <telerik:GridEditCommandColumn HeaderStyle-Width="4%" ButtonType="ImageButton" EditImageUrl="/images/edit.png" />
                <telerik:GridBoundColumn UniqueName="id" DataField="id" HeaderText="id" ReadOnly="True" HeaderStyle-Width="1%" Display="False"> </telerik:GridBoundColumn>
                <telerik:GridDropDownColumn DataField="Band" HeaderText="Band"  UniqueName="Band" ColumnEditorID="GridDropDownListColumnEditor1" HeaderStyle-Width="10%"  ListTextField="description" ListValueField="value" EnableEmptyListItem="true" EmptyListItemValue="0" EmptyListItemText="please select"  FilterControlAltText="Filter callband column" DropDownControlType="RadComboBox" > </telerik:GridDropDownColumn>
        </Columns>
         
        <PagerStyle AlwaysVisible="True" />
        </MasterTableView>
        <ClientSettings>
            <Scrolling AllowScroll="True" ScrollHeight="" SaveScrollPosition="True"></Scrolling>           
        </ClientSettings>
        
        <SortingSettings  EnableSkinSortStyles="false"></SortingSettings>
         
    <PagerStyle Mode="NumericPages" />
</telerik:RadGrid>
<telerik:GridDropDownListColumnEditor ID="GridDropDownListColumnEditor1" runat="server" DropDownStyle-Width="200px" > </telerik:GridDropDownListColumnEditor>

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 15 Nov 2012, 09:51 AM
Hi,

You could resolve your issue by adding additional condition in the ItemDataBound event checking if the e.Item is not in edit mode. Please check the code below.

VB:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs)
    If TypeOf e.Item Is GridDataItem AndAlso Not e.Item.IsInEditMode Then
        Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
        Dim row As DataRowView = DirectCast(e.Item.DataItem, DataRowView)
 
        item("Band").Text = row("Band").ToString()
        item("capoptioname").Text = row("capoptioname").ToString()
    End If
    If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then
        Dim editedItem As GridEditableItem = DirectCast(e.Item, GridEditableItem)
        Dim editMan As GridEditManager = editedItem.EditManager
 
                'your code
       
    End If
End Sub

Thanks,
Shinu.
Tags
Grid
Asked by
Charlotte
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or