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

RadCmoboBox.FindItemByValue Problem

1 Answer 274 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Ravi Kumar
Top achievements
Rank 1
Ravi Kumar asked on 09 Jul 2010, 08:54 AM

Hi,

I,m using RadComboBox with multi columns like “EmployeeStatus” & “StatusID”  and applying search on both the  columns. Once I have selected an employee status, saving StatusID of that status in the database. Its working fine. But my problem is that if I,m loading that statusID from the database and again binding radcomboBox with this id and doing selected true for that id, its not working.

CS Code:

 protected void cboMEStatus_OnItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        {
           List<bocWFEmployeeStatusCollection> listEmpStatus = objlibWFDALController.GetEmployeeStatus();
            if (listEmpStatus != null)
            {
                var status = Enumerable.Empty<bocWFEmployeeStatusCollection>();

                if (utlTypeChecking.IsNumeric(temp))
                {
                    status = from data in listEmpStatus
                             where data.Employee_Status_ID.ToString().StartsWith(temp)
                             select data;

                }
                else
                {
                    status = from data in listEmpStatus
                             where data.Employee_Status_Value.StartsWith(temp, StringComparison.OrdinalIgnoreCase)
                             select data;

                }
                foreach (var item in status)
                {
                    RadComboBoxItem radItem = new RadComboBoxItem();
                    radItem.Text = item.Employee_Status_Value;
                    radItem.Value = item.Employee_Status_ID.ToString();

                    radItem.Attributes.Add("Employee_Status_ID", item.Employee_Status_ID.ToString());
                    cboMEStatus.Items.Add(radItem);
                    radItem.DataBind();
                }

            }
        }

HTML Code:

 <HeaderTemplate>
                                                                <table style="width: 200px" cellspacing="0" cellpadding="0">
                                                                    <tr>
                                                                        <td style="width: 100px;">
                                                                            Status Description
                                                                        </td>
                                                                        <td style="width: 80px;">
                                                                            Status ID
                                                                        </td>
                                                                    </tr>
                                                                </table>
                                                            </HeaderTemplate>
                                                            <ItemTemplate>
                                                                <table border="0" style="width: 200px" cellspacing="0" cellpadding="0">
                                                                    <tr>
                                                                        <td style="width: 100px;">
                                                                            <%# DataBinder.Eval(Container, "Text")%>
                                                                        </td>
                                                                        <td style="width: 80px;">
                                                                            <%# DataBinder.Eval(Container, "Attributes['Employee_Status_ID']")%>
                                                                        </td>
                                                                    </tr>
                                                                </table>
                                                            </ItemTemplate>

********************************************************

 cboMEStatus.FindItemByValue(statusRef.ToString()).Selected = true;

 where statusRef.ToString() is coming from database.

How to Show selected text in combobox with this id.

Please Help

Regards

Ravi

1 Answer, 1 is accepted

Sort by
0
Kalina
Telerik team
answered on 14 Jul 2010, 07:25 AM
Hello Ravi Kumar,

By design when a RadComboBox with enabled Load-On-Demand feature is loaded - it is empty and it has no items. Load-On-Demand fires and populates the control with data if the user types in the input area or clicks on the drop-down toggle image when there are no items in the RadComboBox.

Additionally the RadComboBox items are not accessible on the server-side when loading them on demand and that is why they cannot be accessed using the server-side FindItemByText / Value methods - please take a look at this help article.

I am not familiar with all details of your implementation but I can suggest you add manually a preselected item at RadComboBox input at PageLoad event, if you can obtain the necessary text and value from your database.
Then if you want to edit the selected item - you only need to delete the text at RadComboBox input. Load-On-Demand will fire and when you open the RadComboBox dropdown - all items will be listed and you will be able to select another item.

I hope this helps.

All the best,
Kalina
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
Ravi Kumar
Top achievements
Rank 1
Answers by
Kalina
Telerik team
Share this question
or