Selected value of Combo Box

4 posts, 1 answers
  1. Syed
    Syed avatar
    36 posts
    Member since:
    Nov 2013

    Posted 13 Nov 2013 Link to this post


     

    <telerik:RadComboBox Filter="Contains" runat="server" ID="cmbTechnicalServicePerson" Width="420px"
        MarkFirstMatch="true" DataSourceID="DSGetTechnicalServicePerson" EnableLoadOnDemand="true"
        HighlightTemplatedItems="true" OnClientItemsRequested="UpdateItemCountField"
        OnDataBound="cmbTechnicalServicePerson_DataBound" OnItemDataBound="cmbTechnicalServicePerson_ItemDataBound"
        LabelWidth="100" Label="Technical Service Name:" Skin="Office2010Black" Style="position: absolute; top: 310px; left: 21px; z-index: 6500; height: 16px;" Text="Select  a Value" TabIndex="3">
        <HeaderTemplate>
            <ul>
                <li class="col1">Name</li>
                <li class="col2">Position</li>
                <li class="col2">Unit</li>
            </ul>
        </HeaderTemplate>
        <ItemTemplate>
            <ul>
                <li class="col1">
                    <%# DataBinder.Eval(Container.DataItem, "[FULLNAME]")%></li>
                <li class="col2">
                    <%# DataBinder.Eval(Container.DataItem, "Position")%></li>
                <li class="col3">
                    <%# DataBinder.Eval(Container.DataItem, "[Department]")%></li>
            </ul>
        </ItemTemplate>
        <FooterTemplate>
            A total of
                    <asp:Literal runat="server" ID="RadComboItemsTCount" />
            items
        </FooterTemplate>
     
    </telerik:RadComboBox>

    This is how my combo box set up in aspx page

     

    I wanted to select the value from combo box using vb.net it select the value but the selected text will always “Select  a Value” which is default value.

    This is how I am change the selected value inside the code

    Me.cmbTechnicalServicePerson.SelectedValue = DRProjectDetailsinfo.Item("TechnicalServicePerson")

    Or Me.cmbTechnicalServicePerson.SelectedValue = 12551

    But it is not selecting the text any idea

    Thanks

    Syed

  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 13 Nov 2013 Link to this post

    Hi Syed,

    Please try to set the EmptyMessage property of RadComboBox instead of Text property. The EmptyMessage property enables the ability to set any text in the input field of the control. This text is not visible when the RadComboBox gets the focus and appears again on blur if no item is selected.
    Please have a look into the code snippet to get the Text of Selected Item in Code behind.

    ASPX:
    <telerik:RadComboBox Filter="Contains" runat="server" ID="cmbTechnicalServicePerson"
        Width="420px" MarkFirstMatch="true" DataSourceID="SqlDataSource1" EnableLoadOnDemand="true"
        HighlightTemplatedItems="true" LabelWidth="100" Label="Technical Service Name:"
        Skin="Office2010Black" Style="position: absolute; top: 310px; left: 21px; z-index: 6500;
        height: 16px;" EmptyMessage="Select  a Value" TabIndex="3" OnItemDataBound="cmbTechnicalServicePerson_ItemDataBound"
        OnDataBound="cmbTechnicalServicePerson_DataBound">
    ....
    </telerik:RadComboBox>

    VB:
    Protected Sub cmbTechnicalServicePerson_DataBound(sender As Object, e As EventArgs)
        cmbTechnicalServicePerson.SelectedValue = "12551"
        Dim text As String = cmbTechnicalServicePerson.SelectedItem.Text
    End Sub

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Syed
    Syed avatar
    36 posts
    Member since:
    Nov 2013

    Posted 27 Nov 2013 Link to this post

    Hi There

    I have a another probelm with  RadComboBox

    And definition look like this

    <telerik:RadComboBox Filter="Contains" runat="server" ID="cmbTechnicalServicePerson" Width="420px"

            MarkFirstMatch="true" DataSourceID="DSGetTechnicalServicePerson"

            HighlightTemplatedItems="true" OnClientItemsRequested="UpdateItemCountField"

            OnDataBound="cmbTechnicalServicePerson_DataBound" OnItemDataBound="cmbTechnicalServicePerson_ItemDataBound"

            LabelWidth="100" Label="Technical Service Name:" Skin="Office2010Black" Style="position: absolute; top: 310px; left: 21px; z-index: 6500; height: 16px;" EmptyMessage="Select  a Value" TabIndex="3">

            <HeaderTemplate>

                <ul>

                    <li class="col1">Name</li>

                    <li class="col2">Position</li>

                    <li class="col2">Unit</li>

                </ul>

            </HeaderTemplate>

            <ItemTemplate>

                <ul>

                    <li class="col1">

                        <%# DataBinder.Eval(Container.DataItem, "[FULLNAME]")%></li>

                    <li class="col2">

                        <%# DataBinder.Eval(Container.DataItem, "Position")%></li>

                    <li class="col3">

                        <%# DataBinder.Eval(Container.DataItem, "[Department]")%></li>

                </ul>

            </ItemTemplate>

            <FooterTemplate>

                A total of

                        <asp:Literal runat="server" ID="RadComboItemsTCount" />

                items

            </FooterTemplate>

     

        </telerik:RadComboBox>

    Some time user would like to un select the selected value but this setting  does not allow them. Initial the EmptyMessage="Select  a Value" appear but as soon as they select something they will not be able to unselect to the empty value

    Can someone please give some suggestion?

    Many thanks

    Syed

  5. Nencho
    Admin
    Nencho avatar
    1457 posts

    Posted 02 Dec 2013 Link to this post

    Hello Syed,

    I would suggest you to hook the OnClientBlur client-side event of the RadComboBox and clear the selection of the control, if the text is an empty string. Please consider the following implementation:

    function OnClientBlur(sender) {
              if (sender.get_text() == "") {
                  sender.clearSelection();
              }
          }

    Regards,
    Nencho
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top