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

relate two combobox in editformtemplate

6 Answers 143 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mac
Top achievements
Rank 1
mac asked on 08 Oct 2008, 05:11 PM
hi there. I'm Stuck
wondering if a sample exists that could demonstrate how one would relate two comboboxes when in edit/insert mode within a radgrid.

I have the following source / code combo
Note the gridTemplate is where I was wanting to do my compares.. but if i could do it using the griddropdown feature, that sure would be easier.

I have looked at the demos on relating radcombos, and don't have any issue when working with these independentanly. my issues arise when trying to work with them in a radgrid or similar container. My assumption is that I am not referencing the objects correctly.

thanks for any tips oh and if there is a preferred method, please feel free to state.

my code first:
Sub updateCB2()  
       
        Dim cb2 As RadComboBox = DirectCast(RadGrid1.FindControl("RadComboBox2"), RadComboBox)  
        Dim cb1 As RadComboBox = DirectCast(RadGrid1.FindControl("RadComboBox1"), RadComboBox)  
        cb2.DataSource = functions.dt("Select SubGroup as DepartmentGroup from ATS_CareerTypes where career = '" & cb1.SelectedValue & "'")  
        cb2.DataBind()  
    End Sub  
 
      
    Protected Sub selectTems(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs)  
        updateCB2()  
 
    End Sub 

my source

 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:PHCJobPostsConn %>" 
             SelectCommand="SELECT distinct [Career] FROM [ATS_CareerTypes]" /> 
         <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:PHCJobPostsConn %>" 
             SelectCommand="SELECT distinct [SubGroup] as DepartmentGroup FROM [ATS_CareerTypes]" /> 
              
          
          
                     <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:PHCJobPostsConn %>" 
             SelectCommand="SELECT [Dpt_External], [Dpt_Internal], [Career], [DepartmentGroup], [Position_Type], [Department_Name], [PostingNumber] FROM [ExternalPostings]">  
         </asp:SqlDataSource> 
         <br /> 
         <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateEditColumn="True" DataSourceID="SqlDataSource3" 
             GridLines="None">  
             <MasterTableView   AutoGenerateColumns="False" DataSourceID="SqlDataSource3">  
                 <RowIndicatorColumn> 
                     <HeaderStyle Width="20px" /> 
                 </RowIndicatorColumn> 
                 <ExpandCollapseColumn> 
                     <HeaderStyle Width="20px" /> 
                 </ExpandCollapseColumn> 
                 <Columns> 
                     <telerik:GridCheckBoxColumn DataField="Dpt_External" DataType="System.Boolean" HeaderText="Dpt_External" 
                         SortExpression="Dpt_External" UniqueName="Dpt_External">  
                     </telerik:GridCheckBoxColumn> 
                     <telerik:GridCheckBoxColumn DataField="Dpt_Internal" DataType="System.Boolean" HeaderText="Dpt_Internal" 
                         SortExpression="Dpt_Internal" UniqueName="Dpt_Internal">  
                     </telerik:GridCheckBoxColumn> 
                    <telerik:GridTemplateColumn UniqueName="TemplateColumn" > 
                    <eDITItemTemplate> 
                        &nbsp;<telerik:RadComboBox ID="RadComboBox1" AutoPostBack="true" runat="server"   
                        DataSourceID="SqlDataSource1"   DataTextField="Career" DataValueField="Career"   
                        SelectedValue='<%# bind("career") %>'   
                            OnSelectedIndexChanged="selectTems">  
                            <CollapseAnimation Duration="200" Type="OutQuint" /> 
                        </telerik:RadComboBox> 
                        <telerik:RadComboBox ID="RadComboBox2" runat="server" DataSourceID="SqlDataSource2" 
                            DataTextField="DepartmentGroup" DataValueField="DepartmentGroup"   
                            SelectedValue='<%# Bind("DepartmentGroup") %>'>  
                            <CollapseAnimation Duration="200" Type="OutQuint" /> 
                        </telerik:RadComboBox> 
                        <br /> 
                    </EDITItemTemplate> 
                    </telerik:GridTemplateColumn> 
                      
                     <telerik:GridDropDownColumn UniqueName="CareerGroup" HeaderText="Career"  ListValueField="Career" ListTextField="Career" DataField="Career" DataSourceID="SQLDataSource1" DropDownControlType="DropDownList" /> 
                     <telerik:GridDropDownColumn  HeaderText="SubGroup"  ListValueField="DepartmentGroup" ListTextField="DepartmentGroup" DataField="DepartmentGroup" DataSourceID="SQLDataSource2" DropDownControlType="DropDownList" UniqueName="DepartmentGroup" /> 
                      
                     <telerik:GridBoundColumn DataField="Position_Type" HeaderText="Position_Type" SortExpression="Position_Type" 
                         UniqueName="Position_Type">  
                     </telerik:GridBoundColumn> 
                     <telerik:GridBoundColumn DataField="Department_Name" HeaderText="Department_Name" 
                         SortExpression="Department_Name" UniqueName="Department_Name">  
                     </telerik:GridBoundColumn> 
                     <telerik:GridBoundColumn DataField="PostingNumber" HeaderText="PostingNumber" SortExpression="PostingNumber" 
                         UniqueName="PostingNumber">  
                     </telerik:GridBoundColumn> 
                 </Columns> 
                  
             </MasterTableView> 
                 <FilterMenu EnableTheming="True">  
                 <CollapseAnimation Duration="200" Type="OutQuint" /> 
             </FilterMenu> 
         </telerik:RadGrid><br /> 
         <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
             <AjaxSettings> 
                 <telerik:AjaxSetting AjaxControlID="RadComboBox1">  
                     <UpdatedControls> 
                         <telerik:AjaxUpdatedControl ControlID="RadComboBox1" /> 
                         <telerik:AjaxUpdatedControl ControlID="RadComboBox2" /> 
                     </UpdatedControls> 
                 </telerik:AjaxSetting> 
             </AjaxSettings> 
         </telerik:RadAjaxManager> 



6 Answers, 1 is accepted

Sort by
0
mac
Top achievements
Rank 1
answered on 09 Oct 2008, 05:24 PM
I would like to bump this as I still cannot determine what it is I am doing wrong. I really need to be able to filter the options on the second combo
simplified the issue now.
decided to use formtemplate in EditFormSettings. two radcombos that are databound to the gridDS.

VB:
    Protected Sub RadComboBox2_SelectedIndexChanged1(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs)  
        msg.Text = "changed" 
    End Sub  
 
    Protected Sub RadComboBox1_SelectedIndexChanged1(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs)  
        Try  
            Dim cb2 As RadComboBox = CType(RadGrid1.FindControl("RadComboBox2"), RadComboBox)  
            If cb2 Is Nothing Then ' error checking.  
                msg.Text = "can't find ctrl : " 
            End If  
            Dim cb1 As RadComboBox = DirectCast(RadGrid1.FindControl("RadComboBox1"), RadComboBox)  
            Dim sql As String = "Select SubGroup as DepartmentGroup from ATS_CareerTypes where career = '" & e.Value & "'"  
 
            '   cb2.DataSource = functions.dt(sql) 'this fails as it can't find the combo.  
            'cb2.DataBind() ' cmnted in order to trap errors.  
            msg.Text += sql  
            '   msg.Text = "found it" 
        Catch ex As Exception  
            msg.Text = ex.Message  
        End Try  
 


EditFormTemplate:
<EditFormSettings EditFormType="Template">  
    <FormTemplate> 
    <telerik:RadComboBox ID="RadComboBox1" AutoPostBack="true" runat="server"   
                        DataSourceID="SqlDataSource1"   DataTextField="Career" DataValueField="Career"   
                        SelectedValue='<%# bind("career") %>'   
                            OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged1">  
                            <CollapseAnimation Duration="200" Type="OutQuint" /> 
                        </telerik:RadComboBox> 
                        <telerik:RadComboBox ID="RadComboBox2" runat="server" DataSourceID="SqlDataSource2" 
                            DataTextField="DepartmentGroup" DataValueField="DepartmentGroup"   
                            SelectedValue='<%# Bind("DepartmentGroup") %>' AutoPostBack="True" OnSelectedIndexChanged="RadComboBox2_SelectedIndexChanged1">  
                            <CollapseAnimation Duration="200" Type="OutQuint" /> 
                        </telerik:RadComboBox> 
    </FormTemplate> 
    </EditFormSettings>  

0
Sebastian
Telerik team
answered on 13 Oct 2008, 12:46 PM
Hi mac,

From the code snippets you provided I see that you are attempting to reference the combobox instances inside the edited grid item using RadGrid1.FindControl(id) calls. Note that this is not the proper approach since for each row in the grid there will be difference combobox editors and thus you cannot identify them uniquely (the same case will be when you put those comboboxes inside edit template of MS GridView).

Therefore, you will need to reference the dropdowns through the INamingContainer instance that will be the actual GridEditableItem in this case. Review the implementation from the online resources linked below for more details:

http://demos.telerik.com/ASPNET/Prometheus/Grid/Examples/Programming/AccessingCellsAndRows/DefaultVB.aspx
http://www.telerik.com/help/aspnet-ajax/gridreferencecontrolsinroweditform.html

Regards,
Stephen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
mac
Top achievements
Rank 1
answered on 22 Oct 2008, 04:16 PM
fwiw... neither of the samples provided actually work in their respective VB versions. the prometheus sample has an actual coding error which occurs at the tempdatasource point. the crash is solved if you remove the references to tempdatasource, but then the sample just doesn't do anything. : (.
 
The help document occurs in exactly the same way. ie.. it works... but does not produce the expected result which is to update the related combobox.

anyone have an actual working vb example? Please don't suggest the converter as it results in the same script that doesn't work.

mac
0
Yavor
Telerik team
answered on 23 Oct 2008, 07:13 AM
Hi mac,

Attached to this message, is a small application, which handles a similar setup.
I hope it helps.

Greetings,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
mac
Top achievements
Rank 1
answered on 24 Oct 2008, 08:17 PM
Hi Yavor
the sample provided does not produce the needed vb functionality of filtering items that do not match combo1. I really need to find a vb application that can actually filter for what is selected in combo1. At this point there are still no working vb samples that do this.
Scenario:
dataSource 1/radgrid1 (select Career, Subgoup from table a) returns 40 rows
edit radgrid 1 career combo datasource = (Select Distinct Career from Career_subgroupTable) SelectedValue = Bind("Career")
Subgroup combo DataSource = (Select Distinct Subgroup from Career_Subgroup where Career = Combo1.selectedValue ) SelectedValue = Bind("SubGroup")

if anyone can throw a bone this way... that sure would be nice. working vb code woud be appreciated as none of them so far have worked.

have a great weekend
mac
0
Yavor
Telerik team
answered on 27 Oct 2008, 12:15 PM
Hello mac,

The following forum post contains additional information on another possible approach.
Additionally, you can use the following converter to convert any code snippets.
I hope this gets you started properly.

Best wishes,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
mac
Top achievements
Rank 1
Answers by
mac
Top achievements
Rank 1
Sebastian
Telerik team
Yavor
Telerik team
Share this question
or