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

Hightlight Selected Value in Combobox from textbox

1 Answer 77 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Joe Riley
Top achievements
Rank 1
Joe Riley asked on 08 Sep 2010, 05:43 PM
Trying to implement a RadComboBox that updates as the user types.  There is no problem with the RadComboBox  and populating it with the appropriate data.  Where I am running into a problem is selecting a value if a user tried finding a value via a RadTextBox.  The search performs properly but I need it to select the record found and update a few additional fields. 

See Comment:
'If sASI_Num <> "" then update Label1 & Have _ddCUName be updated with the value selected as it properly is returned by the stored procedure just not selected.

See Code.
    <telerik:RadTextBox Runat="server" id="_txtCUNum" Width="50px">
    </telerik:RadTextBox>
</td>
<td>
    <asp:Label ID="Label1" runat="server" Text="Label" Font-Bold="True" ForeColor="Green"></asp:Label>
</td>
<td>CU Name:
</td>
<td>
    <telerik:RadComboBox id="_ddCUName" Runat="server" Width="450px" EmptyMessage="Type a Credit Union Name" HighlightTemplatedItems="true" height="100px" EnableLoadOnDemand="true" OnItemsRequested="RadComboBoxProduct_ItemsRequested">
        <headertemplate>
            <TABLE>
                <TBODY>
                    <TR><TD>CU Name</TD><TD>City</TD><TD>State</TD></TR>
                </TBODY>
            </TABLE>
        </headertemplate>
        <itemtemplate>
            <TABLE>
                <TBODY>
                    <TR>
                        <TD><%#DataBinder.Eval(Container, "Text")%></TD>
                        <TD><%#DataBinder.Eval(Container, "Attributes['City']")%></TD>
                        <TD><%#DataBinder.Eval(Container, "Attributes['State']")%></TD>
                    </TR>
                </TBODY>
            </TABLE>
        </itemtemplate>
    </telerik:RadComboBox></td>
   Protected Sub RadComboBoxProduct_ItemsRequested(ByVal sender As Object, ByVal e As RadComboBoxItemsRequestedEventArgs)
        Dim sAsi_Num As Object
        If Me._txtCUNum.text = "" Then
            sAsi_Num = DBNull.Value
        Else
            sAsi_Num = Me._txtCUNum.text
        End If
        Try
  
            oConn.Open()
            Dim ocmd As New SqlCommand("sp_getCUSearch", oConn)
            ocmd.CommandType = CommandType.StoredProcedure
            With ocmd.Parameters
                .Add(New SqlParameter("@asi_num", sAsi_Num))
                .Add(New SqlParameter("@SearchStr", e.Text))
            End With
            reader = ocmd.ExecuteReader()
            If reader.HasRows Then
                '-------------------------
                While reader.Read
                    Dim item As New RadComboBoxItem()
  
                    item.Text = DirectCast(reader("cuName"), String)
                    item.Value = reader("asi_num").ToString()
  
                    Dim sCity As String = DirectCast(reader("City"), String)
                    Dim sState As String = DirectCast(reader("State_ID"), String)
  
                    item.Attributes.Add("City", sCity.ToString())
                    item.Attributes.Add("State", sState.ToString())
  
                    'item.Value += ":" + unitPrice.ToString()
  
                    _ddCUName.Items.Add(item)
  
                    item.DataBind()
                    'Next
                End While
'If sASI_Num <> "" then update Label1 & Have _ddCUName be updated with the value selected as it properly is returned by the stored procedure just not selected.
            End If
        Catch ex As Exception
        Finally
            oConn.Close()
        End Try
    End Sub

1 Answer, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 13 Sep 2010, 04:23 PM
Hi Joe Riley,

Your issue originates from the fact that during Load On Demand requests only the only updated control is the RadComboBox itself. Moreover, only its state and a part of it is sent back and forth to the server.

So you cannot access other controls' values that have been changed on the client. Luckily you can use the Context object as a workaround for this limitation.

Secondly you can update the Label on the client, *after* the Load On Demand request returns from the server by handling the client-side ItemsRequested event.

I hope these articles will help you resolve the issues.

Sincerely yours,
Simon
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
ComboBox
Asked by
Joe Riley
Top achievements
Rank 1
Answers by
Simon
Telerik team
Share this question
or