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

RadCombobox in RadGrid

1 Answer 69 Views
Grid
This is a migrated thread and some comments may be shown as answers.
johnson lim
Top achievements
Rank 1
johnson lim asked on 07 Apr 2010, 11:12 PM
Hi,
I have 2 radcombox, RadComboBox A and  RadComboBox B which the data in RadComboBox B is decided by the selection in RadCombobox A. Both the RadCombobox is in RadGrid.
When the grid go into  "Add Record "mode , i fail to populate the data in RadComboBox B for the first item in RadComboBox A.My coding is as below :

  <ajax:RadComboBox runat="server" ID="RadComboA" DataSource="<%# getApp() %>"  OnSelectedIndexChanged="BindSecondCombo" 
                    DataTextField="Selection"  AutoPostBack ="true" 
                    DataValueField="AppId"  
                    SelectedValue='<%# DataBinder.Eval(Container.DataItem, "AppId") %>'></ajax:RadComboBox> 
                    






Public Sub BindSecondCombo(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs) 
 
        Dim radComboA As RadComboBox 
        Dim radComboB As RadComboBox 
        Dim editItem As GridDataInsertItem 
 
 
        radComboA = CType(sender, RadComboBox) 
        editItem = CType(radCombo1.NamingContainer, GridDataInsertItem) 
 
 
 
        radComboB = CType(editItem.FindControl("radComboB"), RadComboBox) 
 
        If radComboB Is Nothing = False Then 
            radComboB.ClearSelection() 
            radComboB.DataSource = getRecordByType(7, radComboA.SelectedValue, "", "", "", "", "") 
            radComboB.DataTextField = "modulename" 
            radComboB.DataValueField = "moduleid" 
            radComboB.DataBind() 
        
        End If 
 
 
    End Sub 




My coding work fine only when the RadGrid go into "Add Record " mode, no selection has been done on RadComboBox A, it fail to populate the data to RaCombobox B based on the first item in  RaCombobox A.
Does anyone has idea on populate the data in  RadComboBox B based on the first item in RadComboBox A  when RadGrid go into "Add Record" mode?

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 08 Apr 2010, 07:20 AM
Hello Johnson,
 
           You can populate the RaCombobox B based on the first item in RaCombobox A by using the following code inside ItemDataBound.

VB:

Protected
 Sub RadGrid1_ItemDataBound(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) '

    If TypeOf e.Item Is GridEditFormInsertItem AndAlso e.Item.OwnerTableView.IsItemInserted Then

        Dim inseritem As GridEditFormInsertItem = DirectCast(e.Item, GridEditFormInsertItem) 
        Dim combo1 As RadComboBox = DirectCast(inseritem.FindControl("RadComboBox1"), RadComboBox) 
        Dim combo2 As RadComboBox = DirectCast(inseritem.FindControl("RadComboBox2"), RadComboBox) 
        combo2.DataSource = getRecordByType(7, radComboA.SelectedValue, """""""", _ 
            ""
        combo2.DataTextField = "modulename" 
        combo2.DataValueField = "moduleid" 
        combo2.DataBind()
    End If

End Sub 
 

Regards
Shinu
Tags
Grid
Asked by
johnson lim
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or