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

How to populate related radcomboxes conditionally.

3 Answers 225 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
gc_0620
Top achievements
Rank 1
gc_0620 asked on 23 Jun 2010, 10:16 PM

Hi,

Environment: VS 2008 SP1, RadControls for ASP.NET AJAX Q1 2010 NET35.

I have 4 related Radcombo boxes. Below are items in each of them and also my expectations. Any help will be appreciated. Thanks

GC_0620
________

RadComboBoxMain Items:

Revision
Transfer

Leave of absence

Termination

______________
RadComboBoxReviewReason (if Selected value from RadComboBoxMain = Revision or Transfer) then Items must be below else Item text will be "".

(if Selected value from = or ) then Items must be below else Item text will be "".

Annual Increment
Change hours
Demotion
Language Differential
Leave of Absence
Obtain UPIN
Other
Promotion
Return from Leave
Salary Adjustment
Therapeutic Differential
Title Change
Transfer to another program

_________________
RadComboBoxLeaveofabsence (if Selected value from RadComboBoxMain = Leave of absence) then Items must be below else Item text will be "".

(if Selected value from = ) then Items must be below else Item text will be "".

Disability
Educational
FMLA
Maternity
Military
Personal
Other

_________
RadComboTeminationReason (if Selected value from RadComboBoxMain = Termination) then Items must be below else Item text will be "".

(if Selected value from = ) then Items must be below else Item text will be "".

Resignation
Discharge
Layoff

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 24 Jun 2010, 07:33 AM
Hello,

I hope the demo itself worthy for you.
Related ComboBoxes


-Shinu.
0
gc_0620
Top achievements
Rank 1
answered on 24 Jun 2010, 07:08 PM

Thanks Shinu but I should be very specific in my origrinal post.

I am using the SQL 2005 backend, In my RadGrid automatic updates/inserts are set to true. Also I am using Form Template Edit Form for insert/update.

RadComboBoxEmploymentStatus:

Active

Leave of absence

Resigned

Revision
Transfer

Termination

______________
RadComboBoxRevisionTransferReasons  (if Selected value from RadComboBoxEmploymentStatus  = Revision or Transfer) then Items must be below else Item text will be "".

Annual Increment
Change hours
Demotion
Language Differential
Leave of Absence
Obtain UPIN
Other
Promotion
Return from Leave
Salary Adjustment
Therapeutic Differential
Title Change
Transfer to another program

_________________
RadComboBoxLeaveofAbsensreasons (if Selected value from RadComboBoxEmploymentStatus = Leave of absence) then Items must be below else Item text will be "".

Disability
Educational
FMLA
Maternity
Military
Personal
Other

_________
RadComboBoxTerminationReasons  (if Selected value from RadComboBoxEmploymentStatus  = Termination) then Items must be below else Item text will be "".

Resignation
Discharge
Layoff

_________
RadComboBoxReemploy  (if Selected value from RadComboBoxEmploymentStatus  = Termination) then Items must be below and  else Item text will be "".

No
Not in this position
Yes



I looked at this article (http://www.telerik.com/help/aspnet-ajax/combo_serversideitemsrequested.html) from Telerik Website to use the ItemsRequested event and LoadOnDemand to bind all dependant RadcomboBoxes but it does not work with Form Template Edit Form as in my project.  Anyway below is my complete aspx code. Thanks again.

Sincerely

Gc_0620
___________

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<html xmlns="http://www.w3.org/1999/xhtml">  
<head runat="server">  
    <title></title>  
</head> 
<body> 
    <form id="form1" runat="server">  
    <div> 
        ''''   
        ''''  
        <editformsettings editformtype="Template">  
                        <FormTemplate> 
                           
                                        <table id="Table3" border="0" class="form-controls">  
                        
                                     <tr> 
                                      '''  
                                      ''''  
                                    <td style="font-size: 11px">  
                                        Change of Payroll Status:  
                                    </td> 
                                    <td> 
                                        <telerik:RadComboBox ID="RadComboBoxEmploymentStatus" runat="server" CssClass="form-label-textbox-controls" 
                                            SelectedValue='<%# Bind("Employment_Status") %>' Skin="Office2007" TabIndex="9" 
                                            Text='<%# Bind("Employment_Status") %>' Width="160px">  
                                            <Items> 
                                                <telerik:RadComboBoxItem runat="server" Text="Active" Value="Active" Selected="true" /> 
                                                <telerik:RadComboBoxItem runat="server" Text="Leave of Absense" Value="Leave of Absense" /> 
                                                <telerik:RadComboBoxItem runat="server" Text="Resigned" Value="Resigned" /> 
                                                <telerik:RadComboBoxItem runat="server" Text="Revision" Value="Revision" /> 
                                                <telerik:RadComboBoxItem runat="server" Text="Terminated" Value="Terminated" /> 
                                                 <telerik:RadComboBoxItem runat="server" Text="Transfer" Value="Transfer" /> 
                                            </Items> 
                                        </telerik:RadComboBox> 
                                    </td> 
                                    </tr> 
                                        <tr> 
                                             <td style="font-size: 11px">  
                                        Revision or Transfer Reasons:  
                                    </td> 
                                    <td> 
                                        <telerik:RadComboBox ID="RadComboBoxRevisionTransferReasons" runat="server" CssClass="form-label-textbox-controls" 
                                            SelectedValue='<%# Bind("RevisionTransferReasons") %>' Skin="Office2007" EnableLoadOnDemand="True" 
 
                                            Text='<%# Bind("RevisionTransferReasons") %>' Width="260px">  
                                            <Items> 
                                            <telerik:RadComboBoxItem runat="server" Text="" Value=""  Selected="true"/>  
                                                <telerik:RadComboBoxItem runat="server" Text="Annual Increment" Value="Annual Increment" /> 
                                                <telerik:RadComboBoxItem runat="server" Text="Change hours" Value="Change hours" /> 
                                                <telerik:RadComboBoxItem runat="server" Text="Demotion" Value="Demotion" /> 
                                                <telerik:RadComboBoxItem runat="server" Text="Language Differential" Value="Language Differential" /> 
                                                <telerik:RadComboBoxItem runat="server" Text="Obtain UPIN" Value="Obtain UPIN" /> 
                                                 <telerik:RadComboBoxItem runat="server" Text="Other" Value="Other" /> 
                                                 <telerik:RadComboBoxItem runat="server" Text="Promotion" Value="Promotion" /> 
                                                <telerik:RadComboBoxItem runat="server" Text="Return from Leave" Value="Return from Leave" /> 
                                                <telerik:RadComboBoxItem runat="server" Text="Salary Adjustment" Value="Salary Adjustment" /> 
                                                <telerik:RadComboBoxItem runat="server" Text="Therapeutic Differential" Value="Therapeutic Differential" /> 
                                                <telerik:RadComboBoxItem runat="server" Text="Title Change" Value="Title Change" /> 
                                                 <telerik:RadComboBoxItem runat="server" Text="Transfer to another program" Value="Transfer to another program" /> 
                                            </Items> 
                                        </telerik:RadComboBox> 
                                    </td> 
                                    <td style="font-size: 11px">  
                                        Leave of Absense reasons:  
                                    </td> 
                                    <td> 
                                        <telerik:RadComboBox ID="RadComboBoxLeaveofAbsensreasons" runat="server" CssClass="form-label-textbox-controls" 
                                            SelectedValue='<%# Bind("LeaveofAbsensereasons") %>' Skin="Office2007" TabIndex="9" 
                                            Text='<%# Bind("LeaveofAbsensereasons") %>' Width="160px">  
                                            <Items> 
                                                <telerik:RadComboBoxItem runat="server" Text="" Value=""  Selected="true"/>  
                                                <telerik:RadComboBoxItem runat="server" Text="Disability" Value="Disability" /> 
                                                <telerik:RadComboBoxItem runat="server" Text="Educational" Value="Educational" /> 
                                                <telerik:RadComboBoxItem runat="server" Text="FMLA" Value="FMLA" /> 
                                                <telerik:RadComboBoxItem runat="server" Text="Maternity" Value="Maternity" /> 
                                                <telerik:RadComboBoxItem runat="server" Text="Military" Value="Military" /> 
                                                 <telerik:RadComboBoxItem runat="server" Text="Other" Value="Other" /> 
                                                 <telerik:RadComboBoxItem runat="server" Text="Personal" Value="Personal" /> 
                                            </Items> 
                                        </telerik:RadComboBox> 
                                    </td> 
                                        </tr> 
                                        <tr> 
                                             <td style="font-size: 11px">  
                                        Termination Reasons:  
                                    </td> 
                                    <td> 
                                        <telerik:RadComboBox ID="RadComboBoxTerminationReasons" runat="server" CssClass="form-label-textbox-controls" 
                                            SelectedValue='<%# Bind("TerminationReasons") %>' Skin="Office2007" EnableLoadOnDemand="True" 
 
                                            Text='<%# Bind("TerminationReasons") %>' Width="160px">  
                                            <Items> 
                                                 <telerik:RadComboBoxItem runat="server" Text="" Value=""  Selected="true"/>  
                                                <telerik:RadComboBoxItem runat="server" Text="Discharge" Value="Discharge" /> 
                                                <telerik:RadComboBoxItem runat="server" Text="Layoff" Value="Leave of Absense" /> 
                                                <telerik:RadComboBoxItem runat="server" Text="Resignation" Value="Resigned" /> 
                                                                                          </Items> 
                                        </telerik:RadComboBox> 
                                    </td> 
                                    <td style="font-size: 11px">  
                                        Re-employ options:  
                                    </td> 
                                    <td> 
                                        <telerik:RadComboBox ID="RadComboBoxReemploy" runat="server" CssClass="form-label-textbox-controls" 
                                            SelectedValue='<%# Bind("Reemploy") %>' Skin="Office2007" TabIndex="9" 
                                            Text='<%# Bind("Reemploy") %>' Width="160px">  
                                            <Items> 
                                               <telerik:RadComboBoxItem runat="server" Text="" Value=""  Selected="true"/>  
                                                <telerik:RadComboBoxItem runat="server" Text="No" Value="No" /> 
                                                <telerik:RadComboBoxItem runat="server" Text="Not in this position" Value="Not in this position" /> 
                                                <telerik:RadComboBoxItem runat="server" Text="Yes" Value="Yes" /> 
                                                  
                                            </Items> 
                                        </telerik:RadComboBox> 
                                    </td> 
                                        </tr> 
                                          
                            </table> 
                        </FormTemplate> 
                    </editformsettings> 
                    ''''  
                    ''''  
    </div> 
    </form> 
</body> 
</html> 
 
0
Kalina
Telerik team
answered on 01 Jul 2010, 07:13 PM
Hello gc_0620,

I am not sure that I understand the exact relation between the five RadComboBoxes that you use.

However I can suggest you a different approach to populate with data the RadComboBoxes related to RadComboBoxEmploymentStatus – you can try to implement OnItemDataBound event of the RadGrid and within the event handler method to obtain instances of RadComboBoxes.
Then you can get the SelectedValue at the RadComboBoxEmploymentStatus and query your database in order to populate with data the related controls:

<telerik:RadGrid ID="RadGrid1" runat="server" Width="600px" OnItemDataBound="OnItemDataBoundHandler" .... >

<EditFormSettings EditFormType="Template">
    <FormTemplate>
        <table id="Table3" border="0" class="form-controls">
            <tr>
                <td style="font-size: 11px">
                    Change of Payroll Status:
                </td>
                <td>
                    <telerik:RadComboBox ID="RadComboBoxEmploymentStatus"
                        runat="server"
                        CssClass="form-label-textbox-controls"
                        SelectedValue='<%# Bind("EmploymentStatus") %>'
                        Skin="Office2007" TabIndex="9"
                        Text='<%# Bind("EmploymentStatus") %>'
                        Width="160px">
                        <Items>
                            <telerik:RadComboBoxItem runat="server"
                                Text="Active" Value="Active"
                                Selected="true" />
                            <telerik:RadComboBoxItem runat="server"
                                Text="Leave of Absense"
                                Value="Leave of Absense" />
                            <telerik:RadComboBoxItem runat="server"
                                Text="Resigned"
                                Value="Resigned" />
                            <telerik:RadComboBoxItem runat="server"
                                Text="Revision"
                                Value="Revision" />
                            <telerik:RadComboBoxItem runat="server"
                                Text="Terminated"
                                Value="Terminated" />
                            <telerik:RadComboBoxItem runat="server"
                                Text="Transfer"
                                Value="Transfer" />
                        </Items>
                    </telerik:RadComboBox>
                </td>
            </tr>

protected void OnItemDataBoundHandler(object sender, GridItemEventArgs e)
{
    if (e.Item.IsInEditMode)
    {
        GridEditableItem item = (GridEditableItem)e.Item;
        if (!(e.Item is IGridInsertItem))
        {
 
            RadComboBox RadComboBoxEmploymentStatus = (RadComboBox)item.FindControl("RadComboBoxEmploymentStatus");
            RadComboBox RadComboBoxRevisionTransferReasons = (RadComboBox)item.FindControl("RadComboBoxRevisionTransferReasons");
            RadComboBox RadComboBoxLeaveofAbsensreasons = (RadComboBox)item.FindControl("RadComboBoxLeaveofAbsensreasons");
            RadComboBox RadComboBoxTerminationReasons = (RadComboBox)item.FindControl("RadComboBoxTerminationReasons");
            RadComboBox RadComboBoxReemploy = (RadComboBox)item.FindControl("RadComboBoxReemploy");
 
            string sqlSelectCommand =
            "SELECT .....  WHERE EmploymentStatus = @status ";
 
            SqlDataAdapter adapter = new SqlDataAdapter(sqlSelectCommand,
                ConfigurationManager.ConnectionStrings["... connection string ..."].ConnectionString);
 
            adapter.SelectCommand.Parameters.AddWithValue("@status", RadComboBoxEmploymentStatus.SelectedValue);
            DataTable dataTable = new DataTable();
            adapter.Fill(dataTable);
 
            RadComboBoxRevisionTransferReasons.DataSource = dataTable;
            RadComboBoxRevisionTransferReasons.DataTextField = "TransferReason";
            RadComboBoxRevisionTransferReasons.DataValueField = "TransferReasonID";
            RadComboBoxRevisionTransferReasons.DataBind();
            ...
            ...
            ...
            ...
 
        }
    }
}

I hope this helps.

Best wishes,
Kalina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
ComboBox
Asked by
gc_0620
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
gc_0620
Top achievements
Rank 1
Kalina
Telerik team
Share this question
or