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

RadCombobox adding empty items on selected index changed

1 Answer 145 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
kd
Top achievements
Rank 1
kd asked on 25 May 2012, 11:38 AM
Hi all,

i have implemented radcombobox with these features sorting , multiple columns for displaying and selected index changed event server side. every thing working fine when first time i select any item from combo but when i am going to select second,third ..... time item from combo than an empty rows added simultaneously
my code is follows
C#
------------------------------------------------
protected void OnOrdersCombo_DataBound(object sender, EventArgs e)
        {
            ((Literal)rcbOrders.Footer.FindControl("RadComboItemsCount")).Text = Convert.ToString(rcbOrders.Items.Count);
            rcbOrders.EmptyMessage = "Please Select";
        }
 
        protected void OnOrdersCombo_ItemRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        {
            rcbOrders.Items.Clear();
 
            string query = string.Empty;
            int OrderNo = 0;
            if (int.TryParse(e.Text, out OrderNo))
                query = @"select
                CCLC_Order_Master.ContactName, CCLC_Order_Master.OrderNo, CCLC_Order_Master.OrderDate,
                Sum(OrderedQty)OrderedQty,sum(isnull(DeliveredQty,0))DeliveredQty,Sum(Amount)Amount
                from CCLC_Order_Master
                inner join CCLC_Order_Detail on CCLC_Order_Detail.OrderNo = CCLC_Order_Master.OrderNo
                WHERE isnull(DeliveredQty,0)> 0  AND CCLC_Order_Master.OrderNo ='" + OrderNo.ToString() +
                "' group by CCLC_Order_Master.OrderNo,CCLC_Order_Master.ContactName, CCLC_Order_Master.OrderNo, CCLC_Order_Master.OrderDate";
            else
                query = @"select
                CCLC_Order_Master.ContactName, CCLC_Order_Master.OrderNo, CCLC_Order_Master.OrderDate,
                Sum(OrderedQty)OrderedQty,sum(isnull(DeliveredQty,0))DeliveredQty,Sum(Amount)Amount
                from CCLC_Order_Master
                inner join CCLC_Order_Detail on CCLC_Order_Detail.OrderNo = CCLC_Order_Master.OrderNo
                WHERE isnull(DeliveredQty,0)> 0  AND ContactName LIKE '" + e.Text + @"%'
                group by CCLC_Order_Master.OrderNo,CCLC_Order_Master.ContactName, CCLC_Order_Master.OrderNo, CCLC_Order_Master.OrderDate";
 
            SqlDataSource1.SelectCommand = query;
            rcbOrders.DataBind();
 
        }
 
        protected void OnOrdersCombo_ItemDataBound(object sender, RadComboBoxItemEventArgs e)
        {
            e.Item.Text = ((DataRowView)e.Item.DataItem)["OrderNo"].ToString();
            e.Item.Value = ((DataRowView)e.Item.DataItem)["OrderNo"].ToString();
        }
 
        protected void OnOrdersCombo_ItemSelected(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            LoadOrderInformation(CCLC_Order_Master.GetDataByKey(long.Parse(rcbOrders.SelectedItem.Value)));
            LoadOrderDetailInformation(long.Parse(rcbOrders.SelectedItem.Value));
            PDealID = (long?)null;
        }
 
JS
----------------------------------------
function UpdateItemCountField(sender, args) {
                sender.get_dropDownElement().lastChild.innerHTML = "A total of " + sender.get_items().get_count() + " items";
            }
 
            function OnOrders_ClientSelectedIndexChanged(sender, eventArgs) {
                var item = eventArgs.get_item();
                var value = item.get_value();
                var text = item.get_text();
                var itemCount = sender.get_items().get_count();
                if (itemCount > 1) {
                    sender.clearItems();
                    sender.clearSelection();
                    var comboItem = new Telerik.Web.UI.RadComboBoxItem();
                    comboItem.set_text(text);
                    comboItem.set_value(value);
                    sender.trackChanges();
                    sender.get_items().add(comboItem);
                    comboItem.select();
                    sender.commitChanges();
                }
                if (itemCount = 1) {
                    sender.trackChanges();
                    sender.set_text(text);
                    sender.set_value(value);
                    sender.commitChanges();
                }
            }
----------------------------------------
 
ASPX
----------------------------------------
<telerik:RadComboBox runat="server" ID="rcbOrders" Height="190px" Width="205px" DropDownWidth="695px"
                            DataSourceID="SqlDataSource1" MarkFirstMatch="true" EnableLoadOnDemand="true"
                            OnClientSelectedIndexChanged="OnOrders_ClientSelectedIndexChanged" HighlightTemplatedItems="true"
                            AutoPostBack="true" OnClientItemsRequested="UpdateItemCountField" OnDataBound="OnOrdersCombo_DataBound"
                            OnItemDataBound="OnOrdersCombo_ItemDataBound" OnItemsRequested="OnOrdersCombo_ItemRequested"
                            OnSelectedIndexChanged="OnOrdersCombo_ItemSelected">
                            <HeaderTemplate>
                                <ul>
                                    <li class="col1">Contact Name</li>
                                    <li class="col2">Order No</li>
                                    <li class="col3">Ordered Qty</li>
                                    <li class="col4">Delivered Qty</li>
                                    <li class="col5">Order Amount</li>
                                    <li class="col6">Order Date</li>
                                </ul>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <ul>
                                    <li class="col1">
                                        <%# DataBinder.Eval(Container.DataItem, "ContactName")%></li>
                                    <li class="col2">
                                        <%# DataBinder.Eval(Container.DataItem, "OrderNo")%></li>
                                    <li class="col3">
                                        <%# DataBinder.Eval(Container.DataItem, "OrderedQty")%></li>
                                    <li class="col4">
                                        <%# DataBinder.Eval(Container.DataItem, "DeliveredQty")%></li>
                                    <li class="col5">
                                        <%# DataBinder.Eval(Container.DataItem, "Amount")%></li>
                                    <li class="col6">
                                        <%# DataBinder.Eval(Container.DataItem, "OrderDate", "{0:dd/MM/yyyy}")%></li>
                                </ul>
                            </ItemTemplate>
                            <FooterTemplate>
                                Total of
                                <asp:Literal runat="server" ID="RadComboItemsCount" />
                                items
                            </FooterTemplate>
                        </telerik:RadComboBox>
                        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CCLCSystem %>"
                            ProviderName="System.Data.SqlClient" SelectCommand="select CCLC_Order_Master.ContactName, CCLC_Order_Master.OrderNo, CCLC_Order_Master.OrderDate,sum(CCLC_Order_Detail.OrderedQty)OrderedQty,sum(isnull(CCLC_Order_Detail.DispatchQty,0))DispatchQty,sum(CCLC_Order_Detail.DeliveredQty)DeliveredQty,sum(CCLC_Order_Detail.Amount)Amount from CCLC_Order_Master inner join CCLC_Order_Detail on CCLC_Order_Detail.OrderNo = CCLC_Order_Master.OrderNo WHERE isnull(DeliveredQty,0)> 0 group by CCLC_Order_Master.OrderNo,CCLC_Order_Master.ContactName, CCLC_Order_Master.OrderNo, CCLC_Order_Master.OrderDate">
                        </asp:SqlDataSource>

 
can any one please fix this issue

1 Answer, 1 is accepted

Sort by
0
Ivana
Telerik team
answered on 30 May 2012, 06:52 AM
Hello Khalid,

I did not manage to replicate the issue you experience, at my end. Attached is the sample page I have tested. Let me know if I am missing something.

Regards,
Ivana
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
Ajax
Asked by
kd
Top achievements
Rank 1
Answers by
Ivana
Telerik team
Share this question
or