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

Bind Multi-column combobox to WebMethod

1 Answer 81 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 19 Jul 2015, 04:41 PM

multi-column RadComboBox  via a web method. 

ASPX

<telerik:RadComboBox  runat="server" ID="RadComboBox1" Width="200px"
        MarkFirstMatch="true"
        EnableLoadOnDemand="true"
        HighlightTemplatedItems="true"
        DroDownCssClass="exampleRadComboBox">
       <HeaderTemplate>
            <tr>
                <th class="col1">Category Name</th>
             <%--   <th class="col2">Some other column</th>--%>
            </tr>
        </HeaderTemplate>
        <ItemTemplate>
            <tr>
                <td class="col1">
                    <%# DataBinder.Eval(Container.DataItem, "Category_Name") %></td>
             <%--   <td class="col2">
                    <%# DataBinder.Eval(Container.DataItem, "Some_Other_Col") %></td>--%>
            </tr>
        </ItemTemplate>
          <WebServiceSettings Method="GetCat" Path="Default.aspx" />
</telerik:RadComboBox>

  Code Behind

 

[WebMethod]
       public static RadComboBoxData GetCatType(RadComboBoxContext context)
       {
           var x =
               "[{'CoachingSessionActivityCategoryID':0,'CoachingSessionActivityTypeID':1000005,'Category_Name':'Skills Conditioning','TeamID':0,'ClubID':1,'Type_Name':'Skills Con - Small Sided Games (Attack)'}]";
 
           var data = JsonConvert.DeserializeObject<DataTable>(x);
 
           RadComboBoxData comboData = new RadComboBoxData();
 
 
           var itemOffset = context.NumberOfItems;
           var endOffset = Math.Min(itemOffset + 10, data.Rows.Count);
 
           comboData.EndOfItems = endOffset == data.Rows.Count;
 
           List<RadComboBoxItemData> result = new List<RadComboBoxItemData>(endOffset - itemOffset);
 
           for (int i = itemOffset; i < endOffset; i++)
           {
               RadComboBoxItemData itemData = new RadComboBoxItemData();
               itemData.Text = data.Rows[i]["Category_Name"].ToString();
               itemData.Value = data.Rows[i]["Category_Name"].ToString();
               result.Add(itemData);
 
           }
           comboData.Items = result.ToArray();
           return comboData;
       }

 

The question is: 

1) How do I bind the combobox to the web method?

2) How do I bind multiple columns to the combo box with the web method?

1 Answer, 1 is accepted

Sort by
0
Andrew
Top achievements
Rank 1
answered on 20 Jul 2015, 08:31 AM

Would delete this post if I could. 

The problem was the web service method I was calling from the combobox and the codebehind. 

<WebServiceSettings Method="GetCat" Path="Default.aspx" />

 

[WebMethod]
       public static RadComboBoxData GetCatType(RadComboBoxContext context)


Their names didn't match up. 

Tags
ComboBox
Asked by
Andrew
Top achievements
Rank 1
Answers by
Andrew
Top achievements
Rank 1
Share this question
or