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

Populate multi-column comboBox from a list of search results (non-data sourced)

2 Answers 129 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
GARY078
Top achievements
Rank 1
GARY078 asked on 09 Oct 2012, 03:14 PM

I have a multi-column comboBox which allows custom text and has "EnableLoadOnDemand" set to true. I want to populate the columns (4 in total) with a list of search results, based on an active directory search method (which returns UserID, Name, Email, Line Manager)

At present, the method works great when the user enters a surname into the text property and clicks a "Search" button (the method is assigned to the OnClick event of the button, obviously.)

What I would like to happen is for the user to enter the first few letters of a surname and the multi-column combobox will load the results on demand.

The results do not come from a datasource, as explained above.

Would this behaviour be possible at all?

As a framework, I have similar code structure to the example found here

Thanks.

 Markup:

<telerik:RadComboBox ID="UserIDComboBox" runat="server" AllowCustomText="True" DropDownWidth="400px" MarkFirstMatch="True" EnableLoadOnDemand="true" OnItemsRequested="UserID_ItemsRequested" OnItemDataBound="UserID_ItemsDataBound"
                  ToolTip="Type first 3 letters of Surname and click Search." Width="200px">
                  <HeaderTemplate>
                      <ul>
                          <li class="col1">User_ID</li>
                          <li class="col2">Name</li>
                          <li class="col3">Email</li>
                          <li class="col4">Line Manager</li>
                      </ul>
                  </HeaderTemplate>
                  <ItemTemplate>
                      <ul>
                      <li class="col1">
                      <%# DataBinder.Eval(Container.DataItem, "UserId") %>
                      </li>
                      <li class="col2">
                      <%# DataBinder.Eval(Container.DataItem, "Name")%>
                      </li>
                      <li class="col3">
                      <%# DataBinder.Eval(Container.DataItem, "Email") %>
                      </li>
                      <li class="col4">
                      <%# DataBinder.Eval(Container.DataItem, "Line Manager") %>
                      </li>
                      </ul>
                  </ItemTemplate>
              </telerik:RadComboBox>

C#

protected void UserID_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        {
            List<User> searchResults = null;
 
            //AD Search (uncomment to test)
            ADSearch ads = new ADSearch();
            searchResults = ads.SearchAD(UserIDComboBox.Text, UserName, Password);
 
            if (null == searchResults)
            {
                UserIDComboBox.Text = "No User Found";
 
            }
            else
            {
                foreach (User adu in searchResults)
                {
                    "UserID field" = adu.UserId;
                    "Name field" = adu.Name;
                    "Email field" = adu.Email;
                   "Manager field" = adu.Manager;
                 }
            }
        }
        protected void UserID_ItemsDataBound(object sender, RadComboBoxItemEventArgs e)
        {
            e.Item.Text = ((DataRowView)e.Item.DataItem)["UserId"].ToString();
            e.Item.Text = ((DataRowView)e.Item.DataItem)["Name"].ToString();
            e.Item.Text = ((DataRowView)e.Item.DataItem)["Email"].ToString();
            e.Item.Text = ((DataRowView)e.Item.DataItem)["Manager"].ToString();
        }

2 Answers, 1 is accepted

Sort by
0
GARY078
Top achievements
Rank 1
answered on 10 Oct 2012, 02:12 PM
I have managed to create a similar behaviour (but not perfect) to what I am aiming for using this code:

I am no longer using an ItemTemplate.

I have to split the strings once they are entered as a comboBox item in order for them to appear under the corresponding headers in the <HeaderTemplate>.


List<User> searchResults = null;
 
            //AD Search (uncomment to test)
 
            ADSearch ads = new ADSearch();
 
            searchResults = ads.SearchAD(e.Text, "UserName", "Password");
 
            if (null == searchResults)
            {
                UserIDComboBox.Text = "No User Found";
            }
            else
            {
                foreach (User adu in searchResults)
                {
                  RadComboBoxItem itemData = new RadComboBoxItem();
                  itemData.Text = adu.UserId.ToString() + adu.Name.ToString() + adu.Email.ToString();
                  UserIDComboBox.Items.Add(itemData);
             }
0
Dimitar Terziev
Telerik team
answered on 12 Oct 2012, 08:06 AM
Hi Gary,

Could you clarify what exactly do you want to improve in the behavior, because as I'm seeing you have managed to achieve the desired functionality?

Greetings,
Dimitar Terziev
the Telerik team
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 their blog feed now.
Tags
ComboBox
Asked by
GARY078
Top achievements
Rank 1
Answers by
GARY078
Top achievements
Rank 1
Dimitar Terziev
Telerik team
Share this question
or