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

RadCombox Not Found In RadGrid

2 Answers 80 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 05 Apr 2010, 01:57 AM
I have 2 radcombobox in radgrid  , radcombobox A and radcombobox B.
The the grid is in add record mode in some situation , radcombobox B content are based on the selection on radcombobox A.

My problem is under the situation where the radcombobox B is not bind to any data, i can't find the radcombobox B by the coding below:
radCombo2 = CType(editItem.FindControl("ddlModuleParentGC"), RadComboBox)radCombo2 = CType(editItem.FindControl("ddlModuleParentGC"), RadComboBox)

My question is as below:
(1).Since the radcombobox B content is based on selection on  radcombobox A , does anyone know how to bind the data to the radcombobox B when the radgrid first go into add record mode? I think this will solve the problem.Pls correct me if i am wrong.

(2) My coding is as below
RadComboBox A=ddlAppID
RadComboBox B= ddlModuleParentGC


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


My code behind is
 <ajax:GridTemplateColumn  UniqueName="GCAppId" HeaderText="Application" SortExpression="AppId" > 
                    <HeaderStyle Width="100px" /> 
                    <ItemTemplate> 
                        <asp:Label ID="lblGCAppId" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "AppId") %>'></asp:Label> 
                    </ItemTemplate> 
                    <EditItemTemplate> 
                        <asp:Label ID="lblGCEAppId" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "AppId") %>'></asp:Label> 
                     
   
                 <ajax:RadComboBox runat="server" ID="ddlAppId" DataSource="<%# getApp() %>"  OnSelectedIndexChanged="BindSecondCombo" 
                    DataTextField="Selection"  AutoPostBack ="true" 
                    DataValueField="AppId"  
                    SelectedValue='<%# DataBinder.Eval(Container.DataItem, "AppId") %>'></ajax:RadComboBox> 
                    
                     
                     
                    </EditItemTemplate> 
                </ajax:GridTemplateColumn> 
 
  
                <ajax:GridTemplateColumn  UniqueName="GCModuleParent" HeaderText="Module Parent" SortExpression="ModuleParent" > 
                    <HeaderStyle Width="100px" /> 
                    <ItemTemplate> 
                     
                        <asp:Label ID="lblModuleParent" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ModuleParent") %>'></asp:Label> 
                    </ItemTemplate> 
                     
                    <EditItemTemplate> 
                     
                       <ajax:RadComboBox runat="server" ID="ddlModuleParentGC" ></ajax:RadComboBox> 
                    <asp:textbox ID="txtModuleParent"  runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ModuleParent") %>'></asp:textbox> 
                         
                    </EditItemTemplate> 
                </ajax:GridTemplateColumn> 






2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 05 Apr 2010, 06:40 AM
Hi Johnson,

Your code will work if you are using "InPlace" EditMode. If you are using EditMode as "EditForms" then you have to use the GridEditFormInsertItem object for accessing controls rather than GridDataInsertItem. Try the code shown below for accessing RadComboBox in insert mode:

VB:

protected void BindSecondCombo(object sender, EventArgs e)
{
   Dim
 radCombo1 As RadComboBox  
   Dim editItem As GridEditFormInsertItem  
   radCombo1 = CType(sender, RadComboBox) 
   editInsertItem = CType(radCombo1.NamingContainer, GridEditFormInsertItem) 
   radCombo2 = CType(editInsertItem.FindControl("combo2"), RadComboBox)
      ...
}

Regards
Princy.
0
johnson lim
Top achievements
Rank 1
answered on 07 Apr 2010, 10:52 PM
Got it, Thanks!!!
Tags
Grid
Asked by
johnson lim
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
johnson lim
Top achievements
Rank 1
Share this question
or