Solved

DataView RowFilter

Posted on 2008-10-15
3
3,119 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now