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

Update fields in insert form template based on the selected index of a radcombobox!

2 Answers 158 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Panayiotis Pelekanos
Top achievements
Rank 1
Panayiotis Pelekanos asked on 09 Feb 2009, 09:49 AM
Hi there,

How can i update fields in my grid when in insert template form mode?
I have a radcombobox bound to a datasource that displays cost types eg: M,M1,M2.....
When the user selects lets say M1 then i want some textboxes of the form eg employee portion,company portion  to updated using calculated data that i will include in my code.
 
I ques my calculations will be placed at :

Protected Sub costtyperad_SelectedIndexChanged(ByVal o As ObjectByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs)  
 
    End Sub 

but how do i access and set values in the other textboxes that are bind in my datasource?

Thanxs in advance
Panos

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 09 Feb 2009, 12:07 PM
Hello Panos,

You can try out the following code to access a TextBox in the FormTemplate on SelectedIndexChanged event of the combobox:
aspx:
 <EditFormSettings EditFormType="Template" > 
            <FormTemplate>             
                <telerik:RadComboBox ID="RadComboBox2" AutoPostBack="true" DataSourceID="SqlDataSource2" DataTextField="ProductName"  runat="server" OnSelectedIndexChanged="RadComboBox2_SelectedIndexChanged"
                 </telerik:RadComboBox> 
                     
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>                     
            </FormTemplate>               
 </EditFormSettings> 

cs:
protected void RadComboBox2_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e) 
    { 
        RadComboBox comboBox = (RadComboBox)o; 
        GridEditableItem dataItem = (GridEditableItem)comboBox.NamingContainer;// To access the InsertFormItem 
        TextBox txtBox = (TextBox)dataItem.FindControl("TextBox1");         
        txtBox.Text = "CustomText"
    } 

Thanks
Princy.
0
Panayiotis Pelekanos
Top achievements
Rank 1
answered on 09 Feb 2009, 12:19 PM
Hi Princy,
I have allready done that
<telerik:RadComboBox ID="costtyperad" Runat="server" DataSourceID="COSTTYPE"   
                                                                 DataTextField="CostType" DataValueField="CostType"   
                                                                 AppendDataBoundItems="True" AutoPostBack="True"   
                                                          onselectedindexchanged="costtyperad_SelectedIndexChanged"   
                                                          SelectedValue='<%# Bind("CostType") %>'>  
                                                                 <Items> 
                                                          <telerik:RadComboBoxItem runat="server" Text="-Please Select Cost Type-"   
                                                                  Value="-Please Select Cost Type-" /> 
                                                                  </Items> 
                                                                 <CollapseAnimation Duration="200" Type="OutQuint" /> 
                                                             </telerik:RadComboBox> 

My question is on what to include in the subroutine:

Protected Sub costtyperad_SelectedIndexChanged(ByVal o As ObjectByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs)  
 
end sub 
The values returned from the combobox are : M,M1,M2,M3 etc
If the user selects M1 then 3 textboxes must filled with some variable data based on the selection.
So how can i make a case scenario on the combobox selection in order to update the template form textboxes:

Here is just some pseudocode i have prepared in order to understand better my requirement:
Dim ACmp As String, AEmp As String, A1Emp As String, A2Emp As String 
        Dim MCmp As String, M1Cmp As String, M2Cmp As String, MEmp As String, M1Emp As String, M2Emp As String 
 
 
       
 
       
       
       
 
        MCmp = 21.36  
        M1Cmp = 32.04  
        M2Cmp = 42.72  
        MEmp = 0  
        M1Emp = 10.68  
        M2Emp = 21.36  
        If Left(selection, 1) = "A" Then 
            Select Case selection.ToString  
                Case "A" 
                    EmployeePortion.Value = AEmp  
                    CompanyPortion.Value = ACmp  
                    total.Value = EmployeePortion.Value + CompanyPortion.Value  
                    YearlyAmount.Value = 12 * total.Value  
                Case "A1" 
                    EmployeePortion.Value = A1Emp  
                    CompanyPortion.Value = ACmp  
                    total.Value = EmployeePortion.Value + CompanyPortion.Value  
                    YearlyAmount.Value = 12 * total.Value  
                Case Else 
                    EmployeePortion.Value = A2Emp  
                    CompanyPortion.Value = ACmp  
                    total.Value = EmployeePortion.Value + CompanyPortion.Value  
                    YearlyAmount.Value = 12 * total.Value  
            End Select 
        ElseIf Left(selection, 1) = "M" Then 
            Select Case selection.ToString  
                Case "M" 
                    EmployeePortion.Value = MEmp  
                    CompanyPortion.Value = MCmp  
                    total.Value = EmployeePortion.Value + CompanyPortion.Value  
                    YearlyAmount.Value = 12 * total.Value  
                Case "M1" 
                    EmployeePortion.Value = M1Emp  
                    CompanyPortion.Value = M1Cmp  
                    total.Value = EmployeePortion.Value + CompanyPortion.Value  
                    YearlyAmount.Value = 12 * total.Value  
                Case Else 
                    EmployeePortion.Value = M2Emp  
                    CompanyPortion.Value = M2Cmp  
                    total.Value = EmployeePortion.Value + CompanyPortion.Value  
                    YearlyAmount.Value = 12 * total.Value  
            End Select 
        End If 
 




Tags
Grid
Asked by
Panayiotis Pelekanos
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Panayiotis Pelekanos
Top achievements
Rank 1
Share this question
or