I would like to use the EnableLoadOnDemand feature of the RadComboBox. I have it working now but would like to use an ItemTemplate also and can't seem to figure out how to get it to work.
Here is the template:
Here is the code behind:
As you can see I have been trying several different approaches (this happens to be where I finally gave up).
Any suggestions would be appreciated.
Thanks
Here is the template:
| <telerik:RadComboBox ID="ddlActivity2" runat="server" Skin="DWDS" EnableEmbeddedSkins="false" MarkFirstMatch="true" Width="728px" |
| Height="320px" ShowMoreResultsBox="true" EnableLoadOnDemand="true" OnItemsRequested="ddlActivity2_ItemsRequested" EnableVirtualScrolling="true" ShowToggleImage="true" |
| DataTextField=Name_Partner |
| HighlightTemplatedItems="true" |
| DataValueField=Activity_ID |
| > |
| <HeaderTemplate> |
| <table style="text-align:left; width:728px;"> |
| <tr> |
| <td style="text-align:left; width: 250px;">Activity</td> |
| <td style="text-align:left; width: 250px">Partner</td> |
| <td style="text-align:left; width: 228px">Category</td> |
| </tr> |
| </table> |
| </HeaderTemplate> |
| <ItemTemplate> |
| <table style="text-align:left; width:728px"> |
| <tr> |
| <td style="text-align:left; width: 250px;"><%# DataBinder.Eval(Container, "Attributes['Name']")%></td> |
| <td style="text-align:left; width: 250px"><%# DataBinder.Eval(Container, "Attributes['PName']") %></td> |
| <td style="text-align:left; width: 228px"><%# DataBinder.Eval(Container, "Attributes['Category_Name']")%></td> |
| </tr> |
| </table> |
| </ItemTemplate> |
| </telerik:RadComboBox> |
Here is the code behind:
| protected void ddlActivity2_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e) |
| { |
| DataTable data = new DataTable(); |
| SqlConnection myCN = new SqlConnection(ConfigurationManager.ConnectionStrings["oConnCF"].ConnectionString); |
| SqlCommand myCom = new SqlCommand(); |
| myCom = new SqlCommand("Activity_ByGrant_ByPartner_Ajax", myCN); |
| SqlDataAdapter da = new SqlDataAdapter(myCom); |
| myCom.CommandType = CommandType.StoredProcedure; |
| myCom.Parameters.Add("@filter", SqlDbType.Text).Value = e.Text; |
| if (uInfo.Access >= 30) |
| { |
| myCom.Parameters.Add("@gid", SqlDbType.Int).Value = _grantID; |
| myCom.Parameters.Add("@pid", SqlDbType.Int).Value = 0; |
| } |
| else |
| { |
| myCom.Parameters.Add("@gid", SqlDbType.Int).Value = _grantID; |
| myCom.Parameters.Add("@pid", SqlDbType.Int).Value = uInfo.PartnerID; |
| } |
| DataSet ds = new DataSet(); |
| da.Fill(ds,"Events"); |
| data = ds.Tables["Events"]; |
| try |
| { |
| int itemsPerRequest = 10; |
| int itemOffset = e.NumberOfItems; |
| int endOffset = itemOffset + itemsPerRequest; |
| if (endOffset > data.Rows.Count) |
| { |
| endOffset = data.Rows.Count; |
| } |
| if (endOffset == data.Rows.Count) |
| { |
| e.EndOfItems = true; |
| } |
| else |
| { |
| e.EndOfItems = false; |
| } |
| for (int i = itemOffset; i < endOffset; i++) |
| { |
| RadComboBoxItem item = new RadComboBoxItem(data.Rows[i]["Name"].ToString(), data.Rows[i]["Activity_ID"].ToString()); |
| item.Attributes.Add("Name", data.Rows[i]["Name"].ToString()); |
| item.Attributes.Add("PName", data.Rows[i]["PName"].ToString()); |
| item.Attributes.Add("Category_Name", data.Rows[i]["Category_Name"].ToString()); |
| ddlActivity2.Items.Add(item); |
| } |
| if (data.Rows.Count > 0) |
| { |
| e.Message = String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", endOffset.ToString(), data.Rows.Count.ToString()); |
| } |
| else |
| { |
| e.Message = "No matches"; |
| } |
| } |
| catch |
| { |
| e.Message = "No matches"; |
| } |
| } |
Any suggestions would be appreciated.
Thanks