ComboBox selectedindexchanged within asp repeater

8 posts, 0 answers
  1. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 02 Oct 2009 Link to this post

    I have a radcombobox that runs some code when the user starts typing in numbers to pull relevant part numbers. Once a user selects a number I need to populate some asp labels. The problem is, these combobox and labels are in an asp repeater because the user can essentially keep adding parts. To see what it does you can go here.
    Basically when the users selects a number to go into the radcombobox I need the two labels (right now say test) to update from the database with the price and part name of that number. I need to run serverside code and update those labels but I can't figure out how to get the rad combo box to execute code since it is in a repeater. I really have no idea how to get started on this. Here is my aspx and vb just for a reference. Thanks,

    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="bulkOrder.aspx.vb" Inherits="devOrthman.bulkOrder"
        MasterPageFile="~/MasterPage.Master" Title="Bulk Ordering" %>

    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

        <script language="javascript" type="text/javascript">
    function OnClientItemsRequested(sender, eventArgs)
       if(sender.get_items().get_count() == 0)

        <div class="ContentPadding">
            <asp:UpdatePanel ID="Panel1" runat="server" UpdateMode="Conditional">
                    <span class="H2Internal">Bulk Ordering</span>
                        <asp:Repeater ID="Repeater1" runat="server">
                                <table cellspacing="5">
                                <tr valign="middle">
                                    <td width="80px">
                                        <asp:Button ID="AddButton" runat="server" Text="Add" CommandName="Add" CausesValidation="True" ValidationGroup ="bulkValidation" />
                                        <asp:Button ID="RemoveBtn" runat="server" Text="Delete" CommandName="Remove" CausesValidation="false"
                                            Visible="false" />
                                    <td width="175px">
                                        <telerik:RadComboBox ID="RadSearchComboBox" runat="server" Width="150px" Height="175px"  ValidationGroup ="bulkValidation"
                                            AllowCustomText="True" ShowToggleImage="False"
                                            ShowMoreResultsBox="true" EnableLoadOnDemand="True" Skin="Telerik" MarkFirstMatch="True"
                                            OnItemsRequested="loadSearch" EnableVirtualScrolling="true" EmptyMessage="Enter Part Number"
                                            ErrorMessage="Value not Found" AutoPostBack="False" OnClientItemsRequested="OnClientItemsRequested">
                                            <CollapseAnimation Duration="100" Type="OutQuint" />
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="*"  ValidationGroup ="bulkValidation"
                                            ControlToValidate="RadSearchComboBox" />
                                    <td width="45px">
                                        <telerik:RadNumericTextBox ID="QtyTextBox" runat="server" MaxLength="3" MaxValue="999"  ValidationGroup ="bulkValidation"
                                            MinValue="1" NumberFormat-DecimalDigits="0" ShowSpinButtons="false" Type="Number"
                                             Width="20px" />
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*"  ValidationGroup ="bulkValidation"
                                            ControlToValidate="QtyTextBox" />
                                    <td class="H2Internal">
                                        Part Name: <asp:Label CssClass ="MainText" id="partName" runat="server" Text="test"></asp:Label>&nbsp;&nbsp;&nbsp;
                                        Price: <asp:Label CssClass ="MainText" id="price" runat="server" Text="test"></asp:Label>
                        <asp:Button ID="Button1" runat="server" Text="All Items to Cart" CausesValidation="True"  ValidationGroup ="bulkValidation"
                        <asp:Label ID="msgLabel" runat="server" Text=""></asp:Label>
                    <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
    VB Code
    Imports Telerik.Web.UI
    Imports System.Data.SqlClient
    Imports System.Net.Mail
    Partial Public Class bulkOrder
        Inherits System.Web.UI.Page
        Shared allItems As ArrayList

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Not Page.IsPostBack Then
                allItems = New ArrayList
                Me.bulkItems = allItems
                Me.bulkItems.Add(New bulkOrderItem())
                Me.Repeater1.DataSource = bulkItems
            End If
        End Sub
        Protected Sub loadSearch(ByVal sender As Object, ByVal e As RadComboBoxItemsRequestedEventArgs)
            Dim connection As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("orthmanConnectionString").ToString)
            Dim selectCommand As New SqlCommand("searchByPartNumber", connection)

            selectCommand.Parameters.AddWithValue("partNumber", e.Text)
            selectCommand.CommandType = CommandType.StoredProcedure
            Dim adapter As New SqlDataAdapter(selectCommand)
            Dim data As New DataTable()

                Dim itemsPerRequest As Integer = 10
                Dim itemOffset As Integer = e.NumberOfItems
                Dim endOffset As Integer = itemOffset + itemsPerRequest
                If endOffset > data.Rows.Count Then
                    endOffset = data.Rows.Count
                End If

                If endOffset = data.Rows.Count Then
                    e.EndOfItems = True
                End If
                Dim i As Integer = itemOffset
                While i < endOffset
                    CType(sender, RadComboBox).Items.Add(New RadComboBoxItem(data.Rows(i)("PartNumber").ToString(), data.Rows(i)("PartId").ToString()))
                    i = i + 1
                End While

                If data.Rows.Count > 0 Then
                    e.Message = [String].Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", endOffset.ToString(), data.Rows.Count.ToString())
                    e.Message = "No Matches"
                End If
                e.Message = "No Matches"
            End Try
        End Sub
        'Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAdd.Click
        '    Me.bulkItems.Add(New bulkOrderItem())
        '    Me.Repeater1.DataSource = bulkItems
        '    Me.Repeater1.DataBind()

        'End Sub
        Protected Sub rptrDatabound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs) Handles Repeater1.ItemDataBound
            Dim index As Integer = e.Item.ItemIndex
            If index < bulkItems.Count And index > -1 Then
                Dim bulkItem As bulkOrderItem
                Dim txtPart As RadComboBox
                Dim qtyPart As Telerik.Web.UI.RadNumericTextBox
                txtPart = CType(e.Item.FindControl("RadSearchComboBox"), RadComboBox)
                qtyPart = CType(e.Item.FindControl("QtyTextBox"), Telerik.Web.UI.RadNumericTextBox)
                bulkItem = CType(bulkItems.Item(index), bulkOrderItem)
                txtPart.Text = bulkItem.itemNumber
                qtyPart.Value = bulkItem.itemQty
                e.Item.FindControl("AddButton").Visible = Not bulkItem.canDelete
                e.Item.FindControl("RemoveBtn").Visible = bulkItem.canDelete
            End If
        End Sub
        Protected Sub storeList()
            Dim index As Integer = 0
            Dim bulkItem As bulkOrderItem
            For Each rptrItem As RepeaterItem In Repeater1.Items
                Dim txtPart As RadComboBox
                Dim qtyPart As Telerik.Web.UI.RadNumericTextBox
                txtPart = CType(rptrItem.FindControl("RadSearchComboBox"), RadComboBox)
                qtyPart = CType(rptrItem.FindControl("QtyTextBox"), RadNumericTextBox)
                bulkItem = CType(bulkItems.Item(index), bulkOrderItem)
                bulkItem.itemNumber = txtPart.Text
                bulkItem.itemQty = qtyPart.Value
                bulkItem.canDelete = Not (rptrItem.FindControl("AddButton").Visible)
                index = index + 1

        End Sub
        'Protected Sub emailAdministrator(ByVal OrderId As String)
        '    Dim msgBody As String
        '    msgBody = "A new order has been placed." & vbCrLf
        '    msgBody &= " Order ID: " & OrderId & vbCrLf
        '    msgBody &= "Please click on the following link to view the details of the order:" & vbCrLf
        '    msgBody &= "" & OrderId

        '    Dim msgTo As String = System.Configuration.ConfigurationManager.AppSettings("sentToAdmin")
        '    Dim msgFrom As String = System.Configuration.ConfigurationManager.AppSettings("sendfrom")
        '    Dim msgSubject As String = "Orthman Online Catalog - New Order Placed"
        '    Try
        '        Dim checkoutMail As New MailMessage(msgFrom, msgTo, msgSubject, msgBody)
        '        Dim mailClient As New SmtpClient()
        '        mailClient.Host = "inteexchange01"
        '        checkoutMail.IsBodyHtml = False
        '        mailClient.Send(checkoutMail)
        '    Catch err As Exception
        '        msgLabel.Text = "An error ocurred, please try again later. <BR/>" & err.ToString
        '    End Try
        'End Sub

        Protected Sub itemChanged(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs)
        End Sub
        Protected Sub rptrCommand(ByVal sender As Object, ByVal e As RepeaterCommandEventArgs) Handles Repeater1.ItemCommand
            Dim index As Integer
            index = e.Item.ItemIndex
            If e.CommandName = "Remove" Then
                Me.Repeater1.DataSource = bulkItems

            ElseIf e.CommandName = "Add" Then
                If Page.IsValid() Then
                    Me.bulkItems.Add(New bulkOrderItem())
                    Me.Repeater1.DataSource = bulkItems
                    Me.Repeater1.Items(index).FindControl("AddButton").Visible = False
                    Me.Repeater1.Items(index).FindControl("RemoveBtn").Visible = True

                End If
            End If
        End Sub
        Protected Sub addToCart(ByVal sender As Object, ByVal e As System.EventArgs)

            If Page.IsValid() Then
                Dim bulkItem As bulkOrderItem
                Dim i As Integer = 0
                While i < bulkItems.Count
                    bulkItem = CType(bulkItems.Item(i), bulkOrderItem)
                    storeInDB(bulkItem.Number, bulkItem.Qty)
                    i = i + 1
                End While
            End If
        End Sub
        Private Property bulkItems() As IList
                Return CType(ViewState("allItems"), ArrayList)
            End Get
            Set(ByVal value As IList)
                ViewState("allItems") = value
            End Set
        End Property
        Protected Sub storeInDB(ByVal partNumber As String, ByVal qty As Integer)
            Dim connString As String = System.Configuration.ConfigurationManager.ConnectionStrings("orthmanConnectionString").ToString
            Dim myConnection As New Data.SqlClient.SqlConnection(connString)
            Dim strSQL = "addPartToCartByNumber"
            Dim insertCommand As New Data.SqlClient.SqlCommand(strSQL, myConnection)
            Dim PartIdParameter As New SqlClient.SqlParameter("@PartNumber", SqlDbType.NVarChar)
            Dim qtyParameter As New SqlClient.SqlParameter("@Quantity", SqlDbType.Int)
            Dim userNameParameter As New SqlClient.SqlParameter("@UserName", SqlDbType.NVarChar)

            insertCommand.CommandType = CommandType.StoredProcedure

            PartIdParameter.Value = partNumber
            qtyParameter.Value = qty
            userNameParameter.Value = User.Identity.Name

            Catch ex As Exception
                'msgLabel.Text = ex.ToString()
            End Try
        End Sub

    End Class
  2. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 06 Oct 2009 Link to this post

    Does anyone have any suggestions on this, I'm still kind of lost.
  3. Vesko
    Vesko avatar
    122 posts
    Member since:
    Mar 2009

    Posted 07 Oct 2009 Link to this post

    Take a look at this forum post - it might give you an idea how to start:

    ComboBox in Repeater - javascript

  4. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 07 Oct 2009 Link to this post

    I don't see how that would work for my instance. If you go to the link I provided you can see what my page looks like and what I mean. Do you have any other suggestions.
  5. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 12 Oct 2009 Link to this post

    I submitted a support ticket.
  6. Veselin Vasilev
    Veselin Vasilev avatar
    2992 posts

    Posted 13 Oct 2009 Link to this post


    I have already replied to your ticket:

    You need to find the labels in the itemChanged (your handler of the SelectedIndexChanged server event) and update them.
    Here is a sample code:

    <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
          <telerik:RadComboBox ID="RadComboBox1"
                <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem1"
                    Value="RadComboBoxItem1" />
                <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem2"
                    Value="RadComboBoxItem2" />
                <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem3"
                    Value="RadComboBoxItem3" />
                <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem4"
                    Value="RadComboBoxItem4" />
                <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem5"
                    Value="RadComboBoxItem5" />
                <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem6"
                    Value="RadComboBoxItem6" />
           <asp:Label ID="lbl1" runat="server"></asp:Label>


    protected void RadComboBox1_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
        Label lbl = (o as Telerik.Web.UI.RadComboBox).NamingContainer.FindControl("lbl1") as Label;
        lbl.Text = e.Text;

    converted to VB:

    Dim lbl As Label = TryCast((TryCast(o, Telerik.Web.UI.RadComboBox)).NamingContainer.FindControl("lbl1"), Label)
    lbl.Text = e.Text

    I hope this helps.

    Best wishes,
    Veselin Vasilev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 13 Oct 2009 Link to this post

    That was it thanks,
  8. vivek
    vivek avatar
    24 posts
    Member since:
    Oct 2010

    Posted 04 Nov 2010 Link to this post

    Hi ,
    I am doing the work with the help of wizard given

    There are several dropdown in page one
    1. Master ddl
    2. ddl1
    I need 3-4 dropdown that need to change after the selection of master dropdown.Now while moving from NEXT to PREVIOUS all the controls withing update panel become disappear.Please help me to solve

    Thanks in Advance.
Back to Top