Hello,
I am trying to add more than one of the type ahead controls here:
http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridincombobox/defaultcs.aspx?product=combobox
I can get a single one to work but for some reason when I try and add the second I cannot get it to populate with data. Funny thing is it is exactly the same as the first one. I can see the columns, it pulls up, looks like it binds but never fills with data. I have tried a number of things to get it to work without issue. I will include my latest iteration of attempting to get this to work below. What am i doing wrong?
Thanks.
I am trying to add more than one of the type ahead controls here:
http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridincombobox/defaultcs.aspx?product=combobox
I can get a single one to work but for some reason when I try and add the second I cannot get it to populate with data. Funny thing is it is exactly the same as the first one. I can see the columns, it pulls up, looks like it binds but never fills with data. I have tried a number of things to get it to work without issue. I will include my latest iteration of attempting to get this to work below. What am i doing wrong?
Thanks.
<%@ Page Title="" Language="C#" MasterPageFile="~/nestLeftNav.master" AutoEventWireup="true" CodeBehind="SKUEditor.aspx.cs" Inherits="PriceTag.SKUEditor" EnableEventValidation="false" %><%--<%@ Register TagPrefix="ebtc" Src="~/controls/skuEditor.ascx" TagName="sku" %>--%><%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %><%@ MasterType VirtualPath="~/nestLeftNav.Master" %><asp:Content ID="Content1" ContentPlaceHolderID="nesthead" runat="server"></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="nestTopNav" runat="server"></asp:Content><asp:Content ID="Content3" ContentPlaceHolderID="nestLeftNavigation" runat="server"></asp:Content><asp:Content ID="Content4" ContentPlaceHolderID="nestMain" runat="server"> <telerik:RadCodeBlock ID="rcb1" runat="server"> <script type="text/javascript"> var grid; var gridPrint; function GridCreated(sender, args) { grid = sender; } function GridPrintCreated(sender, args) { gridPrint = sender; } function RowClicked(sender, args) { //fetch the order id, product name and unit price values from the grid and set them as text in the combobox' input var cellValues = args.getDataKeyValue("ItemCode") + ", " + args.getDataKeyValue("Description"); var combo = $find("<%= rcmbSKU.ClientID %>"); setTimeout(function () { combo.set_text(cellValues); }, 50); } function RowClickedPrintWithSKU(sender, args) { //fetch the order id, product name and unit price values from the grid and set them as text in the combobox' input var cellValues = args.getDataKeyValue("ItemCode") + ", " + args.getDataKeyValue("Description"); var combo = $find("<%= rcmbPrintWithSKU.ClientID %>"); setTimeout(function () { combo.set_text(cellValues); }, 50); } function ShouldInitiateAjaxRequest(comboText) { //if there are three or more symbols entered, filter the data in the dropdown grid if (comboText.length > 2) { $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("LoadFilteredData"); return true; } else { return false; } } function ShouldInitiateAjaxRequestPrint(comboText) { //if there are three or more symbols entered, filter the data in the dropdown grid if (comboText.length > 2) { $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("PrintLoadFilteredData"); return true; } else { return false; } } function HandleOpen(sender, args) { var flag = ShouldInitiateAjaxRequest(sender.get_text()); //cancel the dropdown opening if less than three characters are entered in the combobox' input if (!flag) { args.set_cancel(true); } } function HandleOpenPrint(sender, args) { var flag = ShouldInitiateAjaxRequestPrint(sender.get_text()); //cancel the dropdown opening if less than three characters are entered in the combobox' input if (!flag) { args.set_cancel(true); } } function HandleKeyPressed(sender) { var combo = $find(sender.id); combo.showDropDown(); } </script> </telerik:RadCodeBlock> <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest" RequestQueueSize="3"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="ddlVendor"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="ddlVendorCollections" LoadingPanelID="rajaxLoading" /> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="ddlVendorCollections"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="txtPriceTagDescr" LoadingPanelID="rajaxLoading" /> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="rgridCollections"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="pnlSuccess" LoadingPanelID="rajaxLoading" /> <telerik:AjaxUpdatedControl ControlID="pnlError" LoadingPanelID="rajaxLoading" /> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings> </telerik:RadAjaxManager> <telerik:RadAjaxLoadingPanel ID="rajaxLoading" runat="server"> </telerik:RadAjaxLoadingPanel> <div class="span12"> <div class="page-header"> <h2>SKU Editor</h2> </div> <div class="category-select"> <div class="control-group"> <label class="control-label" for="rcmbSKU">SKU:</label> <div class="controls"> <telerik:RadComboBox ID="rcmbSKU" Width="340px" runat="server" MarkFirstMatch="True" CssClass="SKUCombo" EnableEmbeddedBaseStylesheet="true" EnableEmbeddedSkins="false" AllowCustomText="True" OnClientDropDownOpening="HandleOpen" ExpandAnimation-Type="None" CollapseAnimation-Type="None" DropDownWidth="340px" onkeyup="HandleKeyPressed(this)"> <ItemTemplate> <telerik:RadGrid ID="rgridSKU" Width="325px" runat="server" OnSelectedIndexChanged="rgridSKU_OnSelectedIndexChanged" OnNeedDataSource="rgridSKU_NeedDataSource" EnableEmbeddedBaseStylesheet="true" EnableEmbeddedSkins="true"> <MasterTableView NoMasterRecordsText="" AutoGenerateColumns="False" DataKeyNames="ItemCode, ItemKey, Description" Width="100%" ClientDataKeyNames="ItemCode, ItemKey, Description" TableLayout="Fixed"> <Columns> <telerik:GridBoundColumn HeaderText="SKU" DataField="ItemCode" UniqueName="ItemCode"> <HeaderStyle Width="90px"></HeaderStyle> </telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderText="Description" DataField="Description" UniqueName="Description"> <HeaderStyle Width="215px"></HeaderStyle> </telerik:GridBoundColumn> </Columns> </MasterTableView> <ClientSettings> <ClientEvents OnRowClick="RowClicked" OnGridCreated="GridCreated"></ClientEvents> <Scrolling AllowScroll="true" UseStaticHeaders="true" ScrollHeight="300px"></Scrolling> </ClientSettings> </telerik:RadGrid> </ItemTemplate> <Items> <telerik:RadComboBoxItem runat="server" Text=" "></telerik:RadComboBoxItem> </Items> </telerik:RadComboBox> </div> </div> </div> <div class="category-select"> <div class="control-group"> <label class="control-label" for="ddlVendor">Vendor:</label> <div class="controls"> <asp:DropDownList ID="ddlVendor" runat="server" AutoPostBack="true" onselectedindexchanged="ddlVendor_SelectedIndexChanged" /> </div> </div> </div> <div class="category-select"> <div class="control-group"> <label class="control-label" for="ddlVendorCollections">Vendor Collections:</label> <div class="controls"> <asp:DropDownList ID="ddlVendorCollections" runat="server" AutoPostBack="true" onselectedindexchanged="ddlVendorCollections_SelectedIndexChanged" /> </div> </div> </div> <div class="category-select"> <div class="control-group"> <label class="control-label" for="ddlHeadline">Headline:</label> <div class="controls"> <asp:DropDownList ID="ddlHeadline" runat="server" AutoPostBack="true" /> </div> </div> </div> <div class="category-select"> <div class="control-group"> <label class="control-label" for="txtPriceTagDescr">Price Tag Description: </label> <asp:TextBox ID="txtPriceTagDescr" runat="server"></asp:TextBox> </div> </div> <div class="category-select"> <div class="control-group"> <label class="control-label" for="rcmbSKU">SKU:</label> <div class="controls"> <telerik:RadComboBox ID="RadComboBox1" Width="340px" runat="server" MarkFirstMatch="True" CssClass="SKUCombo" EnableEmbeddedBaseStylesheet="true" EnableEmbeddedSkins="false" AllowCustomText="True" OnClientDropDownOpening="HandleOpen" ExpandAnimation-Type="None" CollapseAnimation-Type="None" DropDownWidth="340px" onkeyup="HandleKeyPressed(this)"> <ItemTemplate> <telerik:RadGrid ID="rgridSKU" Width="325px" runat="server" OnSelectedIndexChanged="rgridSKU_OnSelectedIndexChanged" OnNeedDataSource="rgridSKU_NeedDataSource" EnableEmbeddedBaseStylesheet="true" EnableEmbeddedSkins="true"> <MasterTableView NoMasterRecordsText="" AutoGenerateColumns="False" DataKeyNames="ItemCode, ItemKey, Description" Width="100%" ClientDataKeyNames="ItemCode, ItemKey, Description" TableLayout="Fixed"> <Columns> <telerik:GridBoundColumn HeaderText="SKU" DataField="ItemCode" UniqueName="ItemCode"> <HeaderStyle Width="90px"></HeaderStyle> </telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderText="Description" DataField="Description" UniqueName="Description"> <HeaderStyle Width="215px"></HeaderStyle> </telerik:GridBoundColumn> </Columns> </MasterTableView> <ClientSettings> <ClientEvents OnRowClick="RowClicked" OnGridCreated="GridCreated"></ClientEvents> <Scrolling AllowScroll="true" UseStaticHeaders="true" ScrollHeight="300px"></Scrolling> </ClientSettings> </telerik:RadGrid> </ItemTemplate> <Items> <telerik:RadComboBoxItem runat="server" Text=" "></telerik:RadComboBoxItem> </Items> </telerik:RadComboBox> </div> </div> </div> <div class="category-select"> <div class="control-group"> <label class="control-label" for="rcmbPrintWithSKU">Print with SKU</label> <div class="controls"> <telerik:RadComboBox ID="rcmbPrintWithSKU" Width="340px" runat="server" MarkFirstMatch="True" CssClass="SKUCombo" EnableEmbeddedBaseStylesheet="true" EnableEmbeddedSkins="false" AllowCustomText="True" OnClientDropDownOpening="HandleOpenPrint" ExpandAnimation-Type="None" CollapseAnimation-Type="None" DropDownWidth="340px" onkeyup="HandleKeyPressed(this)"> <ItemTemplate> <telerik:RadGrid ID="rgridPrintWithSKU" Width="325px" runat="server" OnSelectedIndexChanged="rgridPrintWithSKU_OnSelectedIndexChanged" OnNeedDataSource="rgridPrintWithSKU_NeedDataSource" EnableEmbeddedBaseStylesheet="true" EnableEmbeddedSkins="true"> <MasterTableView NoMasterRecordsText="" AutoGenerateColumns="False" DataKeyNames="ItemCode, ItemKey, Description" Width="100%" ClientDataKeyNames="ItemCode, ItemKey, Description" TableLayout="Fixed"> <Columns> <telerik:GridBoundColumn HeaderText="SKU" DataField="ItemCode" UniqueName="ItemCode"> <HeaderStyle Width="90px"></HeaderStyle> </telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderText="Description" DataField="Description" UniqueName="Description"> <HeaderStyle Width="215px"></HeaderStyle> </telerik:GridBoundColumn> </Columns> </MasterTableView> <ClientSettings> <ClientEvents OnRowClick="RowClickedPrintWithSKU" OnGridCreated="GridPrintCreated"></ClientEvents> <Scrolling AllowScroll="true" UseStaticHeaders="true" ScrollHeight="300px"></Scrolling> </ClientSettings> </telerik:RadGrid> </ItemTemplate> <Items> <telerik:RadComboBoxItem runat="server" Text=" "></telerik:RadComboBoxItem> </Items> </telerik:RadComboBox> </div> </div> </div> <div class="category-select"> <div class="control-group"> <div class="controls"> <asp:Button ID="btnSave" runat="server" Text="Button" OnClick="btnSave_OnClick" /> </div> </div> </div> </div></asp:Content>using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Data.SqlClient;using System.Drawing;using System.Web;using System.Web.SessionState;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;using Telerik.Web.UI;using System.Configuration;using Database;namespace PriceTag{ public partial class SKUEditor : PriceTag.classes.ConlinsBasePage { public Database.VendorCollection _dsVendorCollections { get { if (ViewState["VendorCollection"] != null) { return (Database.VendorCollection)ViewState["VendorCollection"]; } else { return null; } } set { ViewState["VendorCollection"] = value; } } public Header parentMasterPage { get { return (Master.parentMaster as Header); } } protected void Page_Load(object sender, EventArgs e) { RadGrid grid = rcmbSKU.Items[0].FindControl("rgridSKU") as RadGrid; RadAjaxManager1.AjaxSettings.AddAjaxSetting(RadAjaxManager1, grid, rajaxLoading); if (!IsPostBack) { fillVendorDropDown(); fillHeadlineCombo(); } } protected DataTable fillItemSKUCombo() { try { Database.Item ds = new Item(); Database.ItemTableAdapters.ItemTableAdapter ta = new Database.ItemTableAdapters.ItemTableAdapter(); ta.Fill(ds._Item, rcmbSKU.Text); //RadComboBox1.DataSource = ds._Item; //RadComboBox1.DataValueField="ItemCode"; //RadComboBox1.DataBind(); return ds._Item; } catch (Exception ex) { throw new System.Exception("There was an issue" + ex.ToString()); } } protected DataTable fillItemPrintWithSKUCombo() { try { Database.Item ds = new Item(); Database.ItemTableAdapters.ItemTableAdapter ta = new Database.ItemTableAdapters.ItemTableAdapter(); ta.Fill(ds._Item, rcmbPrintWithSKU.Text); //RadComboBox1.DataSource = ds._Item; //RadComboBox1.DataValueField="ItemCode"; //RadComboBox1.DataBind(); return ds._Item; } catch (Exception ex) { throw new System.Exception("There was an issue" + ex.ToString()); } } protected void rgridSKU_NeedDataSource(object source, GridNeedDataSourceEventArgs e) { RadGrid grid = source as RadGrid; if (rcmbSKU.Text != "") { //split the combobox text and filter the records in the grid based on the first value in the array, i.e. OrderID String[] vals = rcmbSKU.Text.Split(','); if (vals.Length > 0) { rcmbSKU.Text = vals[0]; } grid.DataSource = fillItemSKUCombo(); //grid.DataSource = GetDataTable("SELECT [Order Details].OrderID, Products.ProductName, [Order Details].UnitPrice FROM Products, [Order Details] " + //"WHERE [Order Details].OrderID LIKE '" + RadComboBox1.Text + "%'" + " AND Products.ProductID=[Order Details].ProductID"); } else { DataTable dt = new DataTable(); dt.Columns.Add("ItemCode"); dt.Columns.Add("Description"); //dt.Columns.Add("ProductName"); //dt.Columns.Add("UnitPrice"); grid.DataSource = dt; } } protected void rgridPrintWithSKU_NeedDataSource(object source, GridNeedDataSourceEventArgs e) { RadGrid gridPrint = source as RadGrid; if (rcmbPrintWithSKU.Text != "") { //split the combobox text and filter the records in the grid based on the first value in the array, i.e. OrderID String[] vals = rcmbPrintWithSKU.Text.Split(','); if (vals.Length > 0) { rcmbPrintWithSKU.Text = vals[0]; } gridPrint.DataSource = fillItemPrintWithSKUCombo(); //grid.DataSource = GetDataTable("SELECT [Order Details].OrderID, Products.ProductName, [Order Details].UnitPrice FROM Products, [Order Details] " + //"WHERE [Order Details].OrderID LIKE '" + RadComboBox1.Text + "%'" + " AND Products.ProductID=[Order Details].ProductID"); } else { DataTable dt = new DataTable(); dt.Columns.Add("ItemCode"); dt.Columns.Add("Description"); //dt.Columns.Add("ProductName"); //dt.Columns.Add("UnitPrice"); gridPrint.DataSource = dt; } } protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e) { RadGrid gridPrint = rcmbPrintWithSKU.Items[0].FindControl("rgridPrintWithSKU") as RadGrid; //detect the filter action if (e.Argument.IndexOf("PrintLoadFilteredData") != -1) { gridPrint.Rebind(); } RadGrid grid = rcmbSKU.Items[0].FindControl("rgridSKU") as RadGrid; //detect the filter action if (e.Argument.IndexOf("LoadFilteredData") != -1) { grid.Rebind(); } } protected void ddlVendor_SelectedIndexChanged(object sender, EventArgs e) { try { fillVendorCollectionDropDown(); searchForItemAttributes(); } catch (Exception ex) { this.parentMasterPage.showError(ex.ToString()); } } protected void ddlVendorCollections_SelectedIndexChanged(object sender, EventArgs e) { try { searchForItemAttributes(); } catch (Exception ex) { this.parentMasterPage.showError("There was an issue when getting the selected Vendor collection value. " + ex.ToString()); } } protected void searchForItemAttributes() { try { string[] strItemCode = rcmbSKU.Text.Split(Convert.ToChar(",")); if (strItemCode.Length > 0) { Database.sp_ItemAttributes_Select ds = new sp_ItemAttributes_Select(); Database.sp_ItemAttributes_SelectTableAdapters.ItemAttributes_SelectTableAdapter ta = new Database.sp_ItemAttributes_SelectTableAdapters.ItemAttributes_SelectTableAdapter(); ta.Fill(ds.ItemAttributes_Select, strItemCode[0], Convert.ToInt32(ddlVendorCollections.SelectedValue.ToString())); if (ds.ItemAttributes_Select.Rows.Count > 0) { txtPriceTagDescr.Text = ds.ItemAttributes_Select.Rows[0]["PriceTagDescription"].ToString(); } } } catch (Exception ex) { throw new System.Exception("There was an issue searching for an existing ItemAttribute. " + ex.ToString()); } } protected void fillVendorCollectionDropDown() { try { string strVendorCode = ddlVendor.SelectedValue.ToString(); Database.sp_VendorCollection_Select ds = new sp_VendorCollection_Select(); Database.sp_VendorCollection_SelectTableAdapters.VendorCollection_SelectTableAdapter ta = new Database.sp_VendorCollection_SelectTableAdapters.VendorCollection_SelectTableAdapter(); ta.Fill(ds.VendorCollection_Select, strVendorCode); ddlVendorCollections.DataSource = ds.VendorCollection_Select; ddlVendorCollections.DataTextField = "CollectionName"; ddlVendorCollections.DataValueField = "CollectionKey"; ddlVendorCollections.DataBind(); } catch (Exception ex) { throw new System.Exception("There was an issue filling the Vendor Collection dropdown. Please contact support or try again. " + ex.ToString()); } } protected void fillHeadlineCombo() { try { Database.sp_Headline_Select ds = new sp_Headline_Select(); Database.sp_Headline_SelectTableAdapters.Headline_SelectTableAdapter ta = new Database.sp_Headline_SelectTableAdapters.Headline_SelectTableAdapter(); ta.Fill(ds.Headline_Select); ddlHeadline.DataSource =ds.Headline_Select; ddlHeadline.DataTextField = "Headline"; ddlHeadline.DataValueField = "HeadlineIdentifier"; ddlHeadline.DataBind(); } catch (Exception ex) { throw new System.Exception("There was an issue filling the Vendor Collection dropdown. Please contact support or try again. " + ex.ToString()); } } protected void fillVendorDropDown() { try { Database.sp_Vendor_Select ds = new sp_Vendor_Select(); Database.sp_Vendor_SelectTableAdapters.Vendor_SelectTableAdapter ta = new Database.sp_Vendor_SelectTableAdapters.Vendor_SelectTableAdapter(); ta.Fill(ds.Vendor_Select); ddlVendor.DataSource = ds.Vendor_Select; ddlVendor.DataTextField = "Name"; ddlVendor.DataValueField = "VendorCode"; ddlVendor.DataBind(); if (ds.Vendor_Select.Count > 0) { ddlVendor.SelectedIndex = ddlVendor.Items.IndexOf(ddlVendor.Items[0]); fillVendorCollectionDropDown(); } } catch (Exception ex) { throw new System.Exception("There was an issue filling the Vendor dropdown. Please contact support or try again. " + ex.ToString()); } } protected void btnSave_OnClick(object sender, EventArgs e) { try { string[] strItemCode = rcmbSKU.Text.Split(Convert.ToChar(",")); if (strItemCode.Length>0) { Database.sp_ItemAttributes_InsertTableAdapters.QueriesTableAdapter ta = new Database.sp_ItemAttributes_InsertTableAdapters.QueriesTableAdapter(); ta.ItemAttributes_Insert(strItemCode[0], txtPriceTagDescr.Text, Convert.ToInt32(ddlVendorCollections.SelectedValue), ddlHeadline.SelectedValue.ToString()); } else { throw new System.Exception("You must choose an item code. "); } this.parentMasterPage.showSuccess("Data was saved successfully. "); } catch (Exception ex) { this.parentMasterPage.showError("There was an issue saving the changes. " + ex.ToString()); } } protected void rgridSKU_OnSelectedIndexChanged(object sender, EventArgs e) { } protected void rgridPrintWithSKU_OnSelectedIndexChanged(object sender, EventArgs e) { } }}