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

Display distinct values

3 Answers 304 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Benjamin
Top achievements
Rank 1
Benjamin asked on 16 Jan 2013, 08:25 AM
How do I set the RadAutoCompleteBox to display only distinct value for a certain column. In my code snippet below, you could see that there are several "NS" values under "Type" column.

protected void Page_Load(object sender, EventArgs e)
        {
                RadAutoCompleteBox1.DataSource = GetData();
                RadAutoCompleteBox1.DataTextField = "Type";
                RadAutoCompleteBox1.DataValueField = "Type";
        }
  
private static DataTable GetData()
        {
            DataTable dt = new DataTable();
            //Set the datafield name
            DataColumn cl = new DataColumn("status");
            dt.Columns.Add(cl);
            cl = new DataColumn("Item_Code");
            dt.Columns.Add(cl);
            cl = new DataColumn("Item_Desc");
            dt.Columns.Add(cl);
            cl = new DataColumn("Vendor_Name");
            dt.Columns.Add(cl);
            cl = new DataColumn("Uom");
            dt.Columns.Add(cl);
            cl = new DataColumn("Moq");
            dt.Columns.Add(cl);
            cl = new DataColumn("Qty");
            dt.Columns.Add(cl);
            cl = new DataColumn("Cur");
            dt.Columns.Add(cl);
            cl = new DataColumn("Price");
            dt.Columns.Add(cl);
            cl = new DataColumn("Total");
            dt.Columns.Add(cl);
            cl = new DataColumn("Type");
            dt.Columns.Add(cl);
  
  
            //Set the static data for row 1
            DataRow dr = dt.NewRow();
            dr[0] = "";
            dr[1] = "07-11-017";
            dr[2] = "PAPER PUNCHER (3 HOLES)";
            dr[3] = "Internal";
            dr[4] = "PC";
            dr[5] = "1";
            dr[6] = "1";
            dr[7] = "SGD";
            dr[8] = "130.00";
            dr[9] = "130.00";
            dr[10] = "NS";
            dt.Rows.Add(dr);
  
  
            //Set the static data for row 2
            dr = dt.NewRow();
            dr[0] = "";
            dr[1] = "07-09-069";
            dr[2] = "BINDING STRIPS A4 (MULTI-COLOUR) (LOT OF 100/50PC) ";
            dr[3] = "Internal";
            dr[4] = "PC";
            dr[5] = "1";
            dr[6] = "1";
            dr[7] = "SGD";
            dr[8] = "60.00";
            dr[9] = "60.00";
            dr[10] = "NS";
            dt.Rows.Add(dr);
  
            //Set the static data for row 3
            dr = dt.NewRow();
            dr[0] = "";
            dr[1] = "01-38-002";
            dr[2] = "LAMINATING MACHINE A4, LMA400";
            dr[3] = "Internal";
            dr[4] = "PC";
            dr[5] = "1";
            dr[6] = "1";
            dr[7] = "SGD";
            dr[8] = "160.00";
            dr[9] = "160.00";
            dr[10] = "NS";
            dt.Rows.Add(dr);
  
            //Set the static data for row 4
            dr = dt.NewRow();
            dr[0] = "";
            dr[1] = "99-09-901";
            dr[2] = "BOLTED CONNECTOR";
            dr[3] = "Internal";
            dr[4] = "PC";
            dr[5] = "10";
            dr[6] = "10";
            dr[7] = "SGD";
            dr[8] = "1.50";
            dr[9] = "15.00";
            dr[10] = "ST";
            dt.Rows.Add(dr);
  
            //Set the static data for row 5
            dr = dt.NewRow();
            dr[0] = "";
            dr[1] = "99-07-905";
            dr[2] = "GUY STRAIN INSULATOR";
            dr[3] = "Internal";
            dr[4] = "PC";
            dr[5] = "100";
            dr[6] = "100";
            dr[7] = "SGD";
            dr[8] = "1.00";
            dr[9] = "100.00";
            dr[10] = "ST";
            dt.Rows.Add(dr);
  
            //Set the static data for row 6
            dr = dt.NewRow();
            dr[0] = "";
            dr[1] = "99-01-505";
            dr[2] = "HOT LINE CLAMP";
            dr[3] = "Internal";
            dr[4] = "PC";
            dr[5] = "500";
            dr[6] = "500";
            dr[7] = "SGD";
            dr[8] = "2.00";
            dr[9] = "1000.00";
            dr[10] = "ST";
            dt.Rows.Add(dr);
  
            return dt;
        }

3 Answers, 1 is accepted

Sort by
0
Cat Cheshire
Top achievements
Rank 1
answered on 21 Jan 2013, 11:06 AM
You should use a column that has unique values for a DataValueField (IDs for example).
0
vikrant
Top achievements
Rank 1
answered on 27 Mar 2015, 05:49 AM
How to bind distinct values in RadAutoCompleteBox ?
0
Nencho
Telerik team
answered on 31 Mar 2015, 06:58 AM
Hello vikrant,

You have several custom implementations available on the matter.
  •  You can use the OnDataSourceSelect event handler of the control, in order to manage your inquiry.
  •  You can specify the distinct query directly in the DataSource control which you use to supply the control with data.
  • You can use a stored procedure as underlying data source for the RadAutoCompleteBox, where your select statement would have the distinct keyword.
  • You can use a custom view, where also this distinct sorting is applied.

SQL SELECT DISTINCT Statement :

http://www.w3schools.com/sql/sql_distinct.asp

 

However, none of the above suggestions are part of the functionality of the control and it's the responsibility of the developer to choose the approach for databinding, which the controls should be using.


Regards,
Nencho
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
AutoCompleteBox
Asked by
Benjamin
Top achievements
Rank 1
Answers by
Cat Cheshire
Top achievements
Rank 1
vikrant
Top achievements
Rank 1
Nencho
Telerik team
Share this question
or