Bind Multi-column combobox to WebMethod

2 posts, 0 answers
  1. Andrew
    Andrew avatar
    6 posts
    Member since:
    Mar 2015

    Posted 19 Jul 2015 Link to this post

    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?

  2. Andrew
    Andrew avatar
    6 posts
    Member since:
    Mar 2015

    Posted 20 Jul 2015 Link to this post

    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. 

  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top