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

ComboBox has duplicated values and set footer message

1 Answer 101 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Headache
Top achievements
Rank 1
Headache asked on 04 Nov 2015, 06:24 AM

I have created a function to combine all ComboBox SQL statement into it,  it is work for showing the data value, but I found that when I click the footer message, it will show up duplicated records in the ComboBox value. Did I miss something? Is it the proper way to do it? Thanks in advance. 

 

My questions are:

1. How to prevent duplicated value? I did try to use EnableAutomaticLoadOnDemand="true", but I have got another error : "There is no assigned datasource. unable to complete callback request".

2. How can I set the paging into the ComboBox like the Demo "Items 1 of 20 out of 90", seems I cannot pass the NumberOfItems parameter into it.

 

My Code as below:

        cbTestA.BindCombobox();
        cbTestB.BindCombobox();
        cbTestC.BindCombobox();


        public void BindCombobox()
        {
            try
            {
                //Default parameters
                AllowCustomText = true;
                Filter = RadComboBoxFilter.Contains;
                MarkFirstMatch = true;
                EnableAutomaticLoadOnDemand = false;
                ShowMoreResultsBox = true;
                EnableVirtualScrolling = true;
                ItemsPerRequest = 20;

                string connectionstring = System.Configuration.ConfigurationManager.ConnectionStrings["Context"].ConnectionString;
                SqlConnection cs = new SqlConnection(connectionstring);
                SqlCommand cmd = new SqlCommand();
                cs.Open();

                switch (this.ID)
                {
                    case "cbTestA":
                        {
                            cmd.CommandText = "select id as dtxt,id as dval from COMPANY";
                        }
                        break;
                    case "cbTestB":
                        {
                            cmd.CommandText = "select id as dtxt,id as dval from COUNTRY";
                        }
                        break;
                    case "cbTestC":
                        {
                            cmd.CommandText = "select id as dtxt,id as dval from USERNAME";
                        }
                        break;
                }

                cmd.Connection = cs;
                DataSet dset = new DataSet();
                SqlDataAdapter dp = new SqlDataAdapter(cmd);
                dp.Fill(dset);

                DataSource = dset;
                DataTextField = "dtxt";
                DataValueField = "dval";
                DataBind();

                //int itemOffset = this.NumberOfItems;
                //int endOffset = Math.Min(itemOffset + ItemsPerRequest, 20); //dset.Rows.Count);
                //this.EndOfItems = endOffset == 20; // data.Rows.Count;
                //this.Message = GetStatusMessage(endOffset, 20); //data.Rows.Count);
            }
            catch (Exception)
            {
                //MessageBox.Show(ex.Message);
            }
        }

1 Answer, 1 is accepted

Sort by
0
Accepted
Nencho
Telerik team
answered on 06 Nov 2015, 02:32 PM
Hello Tim,

The ItemsPerRequest property will be applicable in scenario, where the EnableAutomaticLoadOnDemand property is enabled for the RadComboBox. In such case, you only need to supply the control with the SQLDataSource and the portioning will be automatically calculated.

However, in a scenario, where you need to use ItemsReqested event handler to populate the control with data in simple LoadOnDemand scenario, you have to implement the items per request manually.

Below you can find our online demos, regarding the two cases:

In addition, as we are currently discussing this topic in the support ticket that you have submitted on the matter, I would like to ask you to continue the correspondence in the other thread, in order to avoid duplication.

Regards,
Nencho
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
ComboBox
Asked by
Headache
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Share this question
or