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

[Solved] cascading radcombo in edit mode in radgrid

1 Answer 157 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sanjay
Top achievements
Rank 1
Sanjay asked on 07 Aug 2009, 02:33 PM
Hello,

I have read a few threads in this regards but have not yet got my code working for cascading radcombo in edit mode in radgrid!

Here is my code in aspx page:

 

<telerik:RadGrid ID="gv_Users" runat="server" AutoGenerateColumns="False" GridLines="None" Height="100%" Width="100%" AllowPaging="True" AllowSorting="True" PageSize="15" OnNeedDataSource="gv_Users_NeedDataSource" OnItemCreated="gv_Users_ItemCreated" OnItemDataBound="gv_Users_ItemDataBound">

 

 

<MasterTableView DataKeyNames="UserID,ConID,RoleID,Container_Name,Role_Name">

 

 

<ExpandCollapseColumn Visible="False">

 

 

<HeaderStyle Width="19px" />

 

 

</ExpandCollapseColumn>

 

 

<RowIndicatorColumn Visible="False">

 

 

<HeaderStyle Width="20px" />

 

 

</RowIndicatorColumn>

 

 

<Columns>

 

 

<telerik:GridTemplateColumn UniqueName="col_Edit">

 

 

<HeaderStyle Width="50px" />

 

 

<ItemTemplate>

 

 

<span style="white-space: nowrap;">

 

 

<asp:ImageButton ID="btnEdit" runat="server" meta:resourceKey="btnRole_Edit" CommandName="edit" ToolTip="Edit" SkinID="ImgBtnEdit" />

 

 

<asp:ImageButton ID="btnDelete" runat="server" meta:resourceKey="btnRole_Delete" CommandName="remove" ToolTip="Delete" SkinID="ImgBtnDelete" OnClientClick="return confirm_action('Continue with delete? \nContinuer avec la suppression?');" Visible="false" /></span>

 

 

</ItemTemplate>

 

 

<ItemStyle Width="50px" />

 

 

</telerik:GridTemplateColumn>

 

 

<telerik:GridDropDownColumn UniqueName="ddContainerEdit" ListTextField="Container_Name" ListValueField="Container_Name" DataField="Container_Name" HeaderText="Container_Name" DropDownControlType="RadComboBox" />

 

 

<telerik:GridDropDownColumn UniqueName="ddRoleEdit" ListTextField="Role_Name" ListValueField="Role_Name" DataField="Role_Name" HeaderText="Role_Name" DropDownControlType="RadComboBox" />

 

 

<telerik:GridBoundColumn DataField="UserID" DataType="System.Guid" HeaderText="UserID" UniqueName="col_UserID" meta:resourceKey="col_UserID" SortExpression="UserID" Visible="False">
.......

And here is my code behind page code:

 

 

Protected Sub gv_Users_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles gv_Users.ItemCreated

 

 

If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then

 

 

 

 

 

'the combobox will be the first control in the Controls collection of the corresponding cell

 

 

 

 

 

 

 

 

Dim list As RadComboBox= CType(CType(e.Item, GridEditableItem)("ddContainerEdit").Controls(0), RadComboBox)

 

 

'attach SelectedIndexChanged event for the combobox control

 

 

 

 

list.AutoPostBack =

True

 

 

 

 

 

AddHandler list.SelectedIndexChanged, AddressOf Me.ddContainerEdit_SelectedIndexChanged

 

 

End If

 

 

 

 

 

End Sub

 

 

 

 
My error message:
Unable to cast object of type 'System.Web.UI.WebControls.Literal' to type 'Telerik.Web.UI.RadComboBox'.
I have tried changing the index in Controls(0) from 0 to 3 but it still gives me the same above error.

When I try index 4, My error message:
Specified argument was out of the range of valid values. Parameter name: index

Can you help?

Thanks,
Sanjay


1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 10 Aug 2009, 06:43 AM
Hi Sanjay,

The above given code must be working fine. Have you set the EditFormType property to Template or WebUserControl in the aspx? If so try setting it to AutoGenerated and see whether it is working.

Here is the code which worked on my end.

VB:
 
 
 
    Protected Sub RadGrid1_ItemCreated(ByVal sender As ObjectByVal e As GridItemEventArgs) 
        If (TypeOf e.Item Is GridEditableItem) AndAlso (e.Item.IsInEditMode) Then 
            Dim editItem As GridEditableItem = DirectCast(e.Item, GridEditableItem) 
            Dim combo As RadComboBox = DirectCast(editItem("ddContainerEdit").Controls(0), RadComboBox) 
            AddHandler combo.SelectedIndexChanged, AddressOf combo_SelectedIndexChanged 
            combo.AutoPostBack = True 
        End If 
    End Sub 
    Private Sub combo_SelectedIndexChanged(ByVal o As ObjectByVal e As RadComboBoxSelectedIndexChangedEventArgs) 
       Dim ddContainerEdit As RadComboBox = DirectCast(o, RadComboBox) 
       Dim editItem As GridEditFormItem = DirectCast(ddContainerEdit.NamingContainer, GridEditFormItem) 
      Dim ddRoleEdit As RadComboBox = DirectCast(editItem("ddRoleEdit").Controls(0), RadComboBox) 
   End Sub 
 
 


Best regards
Princy
Tags
Grid
Asked by
Sanjay
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or