Solved

DataView RowFilter

Posted on 2008-10-15
3
3,160 Views
Last Modified: 2013-12-17
I have duplicate values in my dataview and when am binding to the dropdown , i need to populate only unique values onto my dropdown through rowfilter? Any help is appreciated
0
Comment
Question by:venkay
  • 2
3 Comments
 
LVL 12

Expert Comment

by:deanvanrooyen
ID: 22725404
what are you binding from e.g. is the datasource a collection? you can remove duplicate items from the datasource first - probably easier.
0
 
LVL 6

Expert Comment

by:esolve
ID: 22757743
This happens during postback. Sometimes you are calling databind() and it happens automatically. Clearing the dropdownlist before binding is a cheat but not the right way.

 protected void DropDownList1_DataBinding(object sender, EventArgs e)
    {
      DropDownList1.Items.Clear();
    }
0
 
LVL 6

Accepted Solution

by:
esolve earned 125 total points
ID: 22757856
Sorry I take it for granted that you have duplicate items of all values. After reading it again it makes sense that you could have a dataset/resultset with duplicate values because of your query.

Usually a dropdownlist does not have that many items so in this case just use a collection/array to save the distinct values. You will unfortunately have to iterate through the dataset to retrieve your values.

If you want to use a RowFilter I am sure you can do this

DataView dv = ds.DataTable1.DefaultView;
dv.RowFilter = "DISTINCT(Column1)";
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question