Solved

DataView RowFilter

Posted on 2008-10-15
3
3,170 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…

685 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