Display distinct values

4 posts, 0 answers
  1. Benjamin
    Benjamin avatar
    11 posts
    Member since:
    Dec 2012

    Posted 16 Jan 2013 Link to this post

    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;
            }
  2. Cat Cheshire
    Cat Cheshire avatar
    128 posts
    Member since:
    Jun 2010

    Posted 21 Jan 2013 Link to this post

    You should use a column that has unique values for a DataValueField (IDs for example).
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. vikrant
    vikrant avatar
    1 posts
    Member since:
    Mar 2015

    Posted 27 Mar 2015 Link to this post

    How to bind distinct values in RadAutoCompleteBox ?
  5. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 31 Mar 2015 Link to this post

    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.

     
Back to Top