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

Selected value of Combo Box

3 Answers 209 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Syed
Top achievements
Rank 1
Syed asked on 14 Nov 2013, 01:29 AM

 

<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

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 14 Nov 2013, 04:24 AM
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.
0
Syed
Top achievements
Rank 1
answered on 28 Nov 2013, 03:10 AM

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

0
Nencho
Telerik team
answered on 02 Dec 2013, 11:52 AM
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.
Tags
ComboBox
Asked by
Syed
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Syed
Top achievements
Rank 1
Nencho
Telerik team
Share this question
or