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

Radgrid combo box onselectedindexchanged

4 Answers 699 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Ron
Top achievements
Rank 1
Ron asked on 30 May 2011, 12:51 AM
I'm using a radcombo box within radgrid itemtemplate.  How do I set the value of a label control on selectedindexchanged. The label control is not within the grid. there's a screen shot attached to give you an idea.

Thanks,

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 30 May 2011, 07:49 AM
Hello Ron,

You can access the RadComboBox, inside ItemTemplate of RadGrid, in the SelectedIndexChanged Event by using the Sender property. Here is a sample code.

aspx:
<telerik:GridTemplateColumn DataField="CategoryID" HeaderText="Site" SortExpression="SC"
                    UniqueName="SC">
     <ItemTemplate>
         <telerik:RadComboBox ID="RadCombo1" DBSelectedValue='<%# Eval("CategoryID") %>' runat="server"
                            AutoPostBack="true" OnSelectedIndexChanged="RadCombo1_SelectedIndexChanged">
              <Items>
                    <telerik:RadComboBoxItem Text="Item1" Value="1" />
                    <telerik:RadComboBoxItem Text="Item2" Value="2" />
                    <telerik:RadComboBoxItem Text="Item3" Value="3" />
                    <telerik:RadComboBoxItem Text="Item4" Value="4" />
                     <telerik:RadComboBoxItem Text="Item5" Value="5" />
                    <telerik:RadComboBoxItem Text="Item6" Value="6" />
                    <telerik:RadComboBoxItem Text="Item7" Value="7" />
                    <telerik:RadComboBoxItem Text="Item8" Value="8" />
               </Items>
         </telerik:RadComboBox>
      </ItemTemplate>
</telerik:GridTemplateColumn>
. . . . . . . . . . . . . . .
<asp:Label ID="lbl1" runat="server">
</asp:Label>
C#:
protected void RadCombo1_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
  {
      lbl1.Text = (sender as RadComboBox).SelectedValue;    
  }

Thanks,
Shinu.
0
Ron
Top achievements
Rank 1
answered on 30 May 2011, 12:02 PM

Thanks for taking the time Shinu,

I'm not necessararily looking to set the label control to the selected value of the combo box, I'm just trying to set the value of the label when combo box selectedindexchanged and for some strange reason neither of the textbox or label controls outside the grid would work. I did try to implement your solution just to see if it would work and unfurtunately it didnt.  Here's my code; The last line of the code block you can see lblSubtotal is set after a foreach loop, but it never happens on the page.

protected void RadComboBox1_OnSelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
  {
      RadComboBox cmboBx = (sender as RadComboBox);
      GridDataItem dataItem = cmboBx.Parent.Parent as GridDataItem;
      string item = (dataItem["Items"].FindControl("ddlItems") as RadComboBox).Text;
        
      (dataItem["Description"].FindControl("txtDescription") as RadTextBox).Text = InvoiceItems.GetItemDetails(item, 3).Description;
      string price = (dataItem["Price"].FindControl("txtPrice") as RadNumericTextBox).Text = InvoiceItems.GetItemDetails(item, 3).Rate.ToString();
      string qty = (dataItem["Qty"].FindControl("txtQty") as RadNumericTextBox).Text = "1";
      string discount = (dataItem["Discount"].FindControl("txtDiscount") as RadNumericTextBox).Text = "5";
      double total = 0;
      total = (double.Parse(price) * Int32.Parse(qty)) - double.Parse(discount);
      (dataItem["Amount"].FindControl("lblAmount") as Label).Text = total.ToString();

      double subTotal = 0;
      foreach (GridDataItem gridItem in grdInvoiceItems.Items)
      {
          double lineTotal = double.Parse((gridItem["Amount"].FindControl("lblAmount") as Label).Text);
          subTotal += lineTotal;
      }
      lblSubtotal.Text = subTotal.ToString();
  }

0
Dimitar Terziev
Telerik team
answered on 01 Jun 2011, 05:17 PM
Hi Ron,

The code snippet which Shinu has provided is working properly on our side. Please provide us with more information about your specific scenario, also please specify whether you are using ajax or not.

All the best,
Dimitar Terziev
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Jose
Top achievements
Rank 1
answered on 12 Jul 2016, 04:48 PM

Hello Folks,

My scenario is as follow. What i wish to accomplish is to hide/show a row from html table (server side declared) depending of the selected value of the radcomobox. Any help would be appreciated.

        <telerik:RadGrid ID="grdClientList" runat="server" DataSourceID="ClientsDataSource"
            GridLines="None" AllowPaging="True" AllowSorting="True" Skin="Office2010Blue" 
            AutoGenerateColumns="False" CellSpacing="0" PageSize="25"
                ShowFooter="True" 
                onitemdeleted="grdClientList_ItemDeleted" 
                oniteminserted="grdClientList_ItemInserted" 
                onitemupdated="grdClientList_ItemUpdated"
                onupdatecommand="grdClientList_UpdateCommand" 
                oninsertcommand="grdClientList_InsertCommand" 
            onitemdatabound="grdClientList_ItemDataBound" >
            <ClientSettings>
                <Selecting CellSelectionMode="None" AllowRowSelect="false" EnableDragToSelectRows="false"></Selecting>
            </ClientSettings>
            <MasterTableView DataSourceID="ClientsDataSource" DataKeyNames="CiaUno,ClientUno,IsClient" ClientDataKeyNames="CiaUno,ClientUno" CommandItemDisplay="Top" EditMode="PopUp">
                <Columns>
                    <telerik:GridBoundColumn DataField="CiaUno" HeaderText="CIA" UniqueName="CiaUno" Display="false">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="FirstName" HeaderText="FirstName" UniqueName="FirstName" Display="false">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="LastName" HeaderText="LastName" UniqueName="LastName" Display="false">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="MiddleName" HeaderText="MiddleName" UniqueName="MiddleName" Display="false">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="DocumentType" HeaderText="DocumentType" UniqueName="DocumentType" Display="false">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="DocumentNumber" HeaderText="DocumentNumber" UniqueName="DocumentNumber" Display="false">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="MiddleName" HeaderText="MiddleName" UniqueName="MiddleName" Display="false">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="MiddleName" HeaderText="MiddleName" UniqueName="MiddleName" Display="false">
                    </telerik:GridBoundColumn>
                     <telerik:GridBoundColumn DataField="Inactive" HeaderText="Inactive" UniqueName="Inactive" Display="false">
                    </telerik:GridBoundColumn>                                                                                                    
                     <telerik:GridBoundColumn DataField="Direccion" HeaderText="Direccion" UniqueName="Direccion" Display="false">
                    </telerik:GridBoundColumn>
                     <telerik:GridBoundColumn DataField="Provincia" HeaderText="Provincia" UniqueName="Provincia" Display="false">
                    </telerik:GridBoundColumn>
                     <telerik:GridBoundColumn DataField="Sector" HeaderText="Sector" UniqueName="Sector" Display="false">
                    </telerik:GridBoundColumn>
                     <telerik:GridBoundColumn DataField="HousePhone" HeaderText="Telefono Casa" UniqueName="HousePhone" Display="false">
                    </telerik:GridBoundColumn>
                     <telerik:GridBoundColumn DataField="PhoneNumber" HeaderText="Telefono Trabajo" UniqueName="PhoneNumber" Display="false">
                    </telerik:GridBoundColumn>
                     <telerik:GridBoundColumn DataField="MobilePhone" HeaderText="Telefono Celular" UniqueName="MobilePhone" Display="false">
                    </telerik:GridBoundColumn>
                     <telerik:GridBoundColumn DataField="EMail" HeaderText="Correo Electronico" UniqueName="EMail" Display="false">
                    </telerik:GridBoundColumn>
                     <telerik:GridBoundColumn DataField="SpouseName" HeaderText="Nombre Esposa" UniqueName="SpouseName" Display="false">
                    </telerik:GridBoundColumn>
                     <telerik:GridBoundColumn DataField="DateOfBirth" HeaderText="Fecha Nacimiento" UniqueName="DateOfBirth" Display="false">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="FullName" HeaderText="<%$ Resources:AMSResource, SearchControl_lblClientName %>" SortExpression="FullName"
                        UniqueName="FullName"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="ClientType" HeaderText="ClientType" UniqueName="ClientType">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="ClientReference" HeaderText="ClientReference" UniqueName="ClientReference">
                    </telerik:GridBoundColumn>
                    <telerik:GridImageColumn UniqueName="IsClient"  DataType="System.String"  ImageAlign="Middle" ImageHeight="25px" ImageWidth="25px" HeaderText="Es Cliente?">
                        <ItemStyle Width="50px" />
                    </telerik:GridImageColumn>
                    <telerik:GridEditCommandColumn UniqueName="btnEdit" ButtonType="ImageButton">
                        <ItemStyle Width="25px" />
                    </telerik:GridEditCommandColumn>
                    <telerik:GridButtonColumn ButtonType="ImageButton" UniqueName="btnDelete" CommandName="Delete">
                        <ItemStyle Width="25px" />
                    </telerik:GridButtonColumn>
                    <telerik:GridButtonColumn ButtonType="ImageButton" UniqueName="btnQuote" CommandName="Quotes">
                        <ItemStyle Width="25px"/>
                    </telerik:GridButtonColumn>
                </Columns>
                <EditFormSettings EditFormType="Template" CaptionFormatString="Cliente / Prospecto: {0}" CaptionDataField="FullName"
                     PopUpSettings-Height="500px" PopUpSettings-Width="600px">
                    <FormTemplate>
                        <fieldset>
                            <legend>Mantenimiento Clientes</legend>
                            <table id="tblClient" runat="server" cellspacing="2" cellpadding="2" width="100%" border="0" rules="none" style="border-collapse: collapse;">
                                <tr>
                                    <td><label>Tipo Cliente:</label></td>
                                    <td></td>
                                    <td>
                                        <telerik:RadComboBox ID="ddlTipo" runat="server" onselectedindexchanged="ddlTipo_SelectedIndexChanged" AutoPostBack="True" 
                                            DataSourceID="ClientTypeDataSource" DataTextField="Description" DataValueField="TypeUno" 
                                            EmptyMessage="Tipo cliente..." >
                                        </telerik:RadComboBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td><label>Nombre:</label></td>
                                    <td></td>
                                    <td>
                                        <telerik:RadTextBox ID="txtFullName" runat="server" Width="400px"></telerik:RadTextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td><label>Primer Nombre:</label></td>
                                    <td></td>
                                    <td>
                                       <telerik:RadTextBox ID="txtFirstName" runat="server" Width="400px"></telerik:RadTextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td><label>Segundo Nombre:</label></td>
                                    <td></td>
                                    <td>
                                        <telerik:RadTextBox ID="txtMiddleName" runat="server" Width="400px"></telerik:RadTextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td><label>Apellidos:</label></td>
                                    <td></td>
                                    <td>
                                        <telerik:RadTextBox ID="txtLastName" runat="server" Width="400px"></telerik:RadTextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td><label>Referido via:</label></td>
                                    <td></td>
                                    <td>
                                        <telerik:RadComboBox ID="ddlReferenceBy" runat="server" 
                                            DataSourceID="ClientReferenceDataSource"  DataTextField="Description" DataValueField="ReferenceUno"
                                            EmptyMessage="Referencia...">
                                        </telerik:RadComboBox>

                                    </td>
                                </tr>
                                <tr>
                                    <td><label>Tipo de Documento:</label></td>
                                    <td></td>
                                    <td>
                                    <asp:RadioButtonList ID="rblDocumentType" runat="server" RepeatDirection="Horizontal">
                                        <asp:ListItem Selected="True" Value="1">Cedula</asp:ListItem>
                                        <asp:ListItem Value="2">Pasaporte</asp:ListItem>
                                        <asp:ListItem Value="3">RNC</asp:ListItem>
                                    </asp:RadioButtonList>
                                    </td>
                                </tr>
                                <tr>
                                    <td><label>Numero de Documento:</label></td>
                                    <td></td>
                                    <td>
                                        <%--<asp:TextBox ID="txtDocumentNumber" runat="server"></asp:TextBox>--%>
                                        <telerik:RadMaskedTextBox ID="txtDocumentNumber" NumericRangeAlign="Right" 
                                            SelectionOnFocus="SelectAll" runat="server" Mask="#############"
                                            Width="100px" DisplayMask="#############" EmptyMessage="Numero documento" 
                                            Wrap="False" style="top: 0px; left: 0px">
                                        </telerik:RadMaskedTextBox>
                                    </td>

                                </tr>
                                <tr>
                                    <td><label>Estatus:</label></td>
                                    <td></td>
                                    <td>
                                        <asp:RadioButtonList ID="rblInactive" runat="server" RepeatDirection="Horizontal">
                                            <asp:ListItem Selected="True" Value="0">Activo</asp:ListItem>
                                            <asp:ListItem Value="1">Inactivo</asp:ListItem>
                                        </asp:RadioButtonList>
                                    </td>
                                </tr>
                                <tr>
                                    <td><label>Sexo:</label></td>
                                    <td></td>
                                    <td>
                                        <asp:RadioButtonList ID="rblSex" runat="server" RepeatDirection="Horizontal">
                                            <asp:ListItem Selected="True" Value="0">Masculino</asp:ListItem>
                                            <asp:ListItem Value="1">Femenino</asp:ListItem>
                                        </asp:RadioButtonList>
                                    </td>
                                </tr>
                                <tr>
                                    <td><label>Correo Electronico:</label></td>
                                    <td></td>
                                    <td>
                                        <telerik:RadTextBox ID="txtEMail" runat="server" Width="400px"></telerik:RadTextBox>
                                        <br />
                                        <asp:RegularExpressionValidator id="emailValidator" runat="server" Display="Dynamic"
                                            ErrorMessage="Por favor, digite una direccion de correos valida."
                                            ValidationExpression="^[\w\.\-]+@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]{1,})*(\.[a-zA-Z]{2,3}){1,2}$"
                                            ControlToValidate="txtEMail">
                                        </asp:RegularExpressionValidator>
                                    </td>
                                </tr>
                                <tr> 
                                    <td><label>Telefono:</label></td>
                                    <td></td>
                                    <td>
                                        <telerik:RadMaskedTextBox ID="txtPhoneNumber" runat="server" Mask="(###)-###-####"></telerik:RadMaskedTextBox>
                                    </td>
                                </tr>
                                <tr valign="top" style="white-space:nowrap;">
                                    <td><label>Fecha Nacimiento:</label></td>
                                    <td></td>
                                    <td>
                                        <telerik:RadNumericTextBox ID="txtDia" runat="server" ShowSpinButtons="true" 
                                            MaxLength="2" MinValue="1" MaxValue="31" Width="40px" ToolTip="Dia" DataType="System.Int16" >
                                            <NumberFormat GroupSeparator="" DecimalDigits="0" /> 
                                        </telerik:RadNumericTextBox><b>/</b>
                                        <telerik:RadNumericTextBox ID="txtMes" runat="server" ShowSpinButtons="true" 
                                            MaxLength="2" MinValue="1" MaxValue="12" Width="40px" ToolTip="Mes" DataType="System.Int16">
                                            <NumberFormat GroupSeparator="" DecimalDigits="0" /> 
                                        </telerik:RadNumericTextBox><b>/</b>
                                        <telerik:RadNumericTextBox ID="txtAno" runat="server" ShowSpinButtons="true" 
                                            MaxLength="4" MinValue="1900" MaxValue="2099" Width="70px" ToolTip="Año" DataType="System.Int16">
                                            <NumberFormat GroupSeparator="" DecimalDigits="0" /> 
                                        </telerik:RadNumericTextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="3">
                                        <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? " Salvar " : " Salvar " %>'
                                            runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
                                        </asp:Button>&nbsp;
                                        <asp:Button ID="btnCancel" Text="Cancelar" runat="server" CausesValidation="False" CommandName="Cancel"></asp:Button>
                                    </td>
                                </tr>
                            </table>
                        </fieldset>

                    </FormTemplate>
                </EditFormSettings>
            </MasterTableView>
        </telerik:RadGrid>

 

       <asp:ObjectDataSource ID="ClientsDataSource" runat="server" SelectMethod="GatherClients" TypeName="AMS.Client.ClientList">
            <SelectParameters>
                <asp:Parameter Name="CiaUno" Type="Int32" />
            </SelectParameters>
            <InsertParameters>
                <asp:Parameter Name="CiaUno" Type="Int32" />
                <asp:Parameter Name="ClientType" Type="Int32" />
            </InsertParameters>
        </asp:ObjectDataSource> 
     <asp:ObjectDataSource ID="ClientTypeDataSource" runat="server" SelectMethod="ClientTypeList" TypeName="AMS.Client.ClientList">
        <SelectParameters>
            <asp:Parameter Name="CiaUno" Type="Int32" />
        </SelectParameters>
    </asp:ObjectDataSource>  
    <asp:ObjectDataSource ID="ClientReferenceDataSource" runat="server" SelectMethod="ClientReferenceList" TypeName="AMS.Client.ClientList">
        <SelectParameters>
            <asp:Parameter Name="CiaUno" Type="Int32" />
        </SelectParameters>
    </asp:ObjectDataSource>  

protected void ddlTipo_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            RadComboBox tipo = (sender as RadComboBox);
            GridDataItem oItem = tipo.NamingContainer as GridDataItem;

            System.Web.UI.HtmlControls.HtmlTable oTbl = oItem["Items"].FindControl("tblClient") as System.Web.UI.HtmlControls.HtmlTable;

            //rblDocumentType.SelectedIndex = -1;

            if (tipo.SelectedValue == "1")
            {
                oTbl.Rows[1].Visible = false;
                oTbl.Rows[2].Visible = true;
                oTbl.Rows[3].Visible = true;
                oTbl.Rows[4].Visible = true;
                oTbl.Rows[5].Visible = true;
                oTbl.Rows[6].Visible = true;
                oTbl.Rows[7].Visible = true;
                oTbl.Rows[8].Visible = true;
                oTbl.Rows[9].Visible = true;
                oTbl.Rows[10].Visible = true;
                oTbl.Rows[11].Visible = true;
                oTbl.Rows[12].Visible = true;
                //rblDocumentType.Items[0].Enabled = true;
                //rblDocumentType.Items[1].Enabled = true;
                //rblDocumentType.Items[2].Enabled = false;
            }
            else
            {
                oTbl.Rows[1].Visible = true;
                oTbl.Rows[2].Visible = false;
                oTbl.Rows[3].Visible = false;
                oTbl.Rows[4].Visible = false;
                oTbl.Rows[5].Visible = true;
                oTbl.Rows[6].Visible = true;
                oTbl.Rows[7].Visible = true;
                oTbl.Rows[8].Visible = true;
                oTbl.Rows[9].Visible = false;
                oTbl.Rows[10].Visible = true;
                oTbl.Rows[11].Visible = true;
                oTbl.Rows[12].Visible = false;
               // rblDocumentType.Items[0].Enabled = false;
                //rblDocumentType.Items[1].Enabled = false;
                //rblDocumentType.Items[2].Enabled = true;
                //rblDocumentType.Items[2].Selected = true;
            }
        }

 

 

Tags
ComboBox
Asked by
Ron
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ron
Top achievements
Rank 1
Dimitar Terziev
Telerik team
Jose
Top achievements
Rank 1
Share this question
or