public void BindGrid()
{
UpdateSelectStmt();
adptr_LocationSummary.Fill(dsLocationSummary1);
//CityChooser is a DropdownList
CityChooser.DataSource = dsLocationSummary1;
CityChooser.DataTextField = "City";
CityChooser.DataValueField = "City";
CityChooser.DataBind();
//ListItemCollection cities = CityChooser.Items;
//do something here to remove duplicates
dg_LocationSummary.DataBind();
}
Now the problem is that the CityChooser is getting a city for every row, but
what I'd like is to show only unique cities. I couldn't find a flag for
getting only unique items. I can seem to think of a clean, efficient, way to
remove all the duplicates without copying the items into a new list and
binding (though it wouldn't technically be binding I suppose) the
CityChooser to the new list.
Thanks
Brian
bill
"brian richards" <brian...@hotmail.com> wrote in message
news:u0Es8jpW...@TK2MSFTNGP10.phx.gbl...
You could filter your initial select statement by using the keyword
DISTINCT.
SELECT DISTINCT citynames FROM tblEntries
If you can't filter the records at the database request level then you can
always build a view in a similar fashion from those records.
Dim DataView As New DataView(dsLocationSummary1.Tables(0))
DataView.RowFilter = "DISTINCT citynames ASC"
CityChooser.DataSource = DataView;
CityChooser.DataTextField = "City";
CityChooser.DataValueField = "City";
Sincerely,
--
S. Justin Gengo, MCP
Web Developer
Free code library at:
www.aboutfortunate.com
"Out of chaos comes order."
Nietzche
"brian richards" <brian...@hotmail.com> wrote in message
news:u0Es8jpW...@TK2MSFTNGP10.phx.gbl...
>.
>
Thanks
Brian
"William F. Robertson, Jr." <wfrob...@kpmg.com> wrote in message
news:ufEZLHqW...@tk2msftngp13.phx.gbl...
But I get the same results. I could just do a new query: "select distinct
city from table where state = 'NC'" or whatever, but I'm trying not to
access the database again if at all possible.
I also tried:
public void BindGrid()
{
UpdateSelectStmt();
adptr_LocationSummary.Fill(dsLocationSummary1);
CityChooser.DataSource = dsLocationSummary1;
CityChooser.DataTextField = "City";
CityChooser.DataValueField = "City";
CityChooser.DataBind();
for(int i = 0;i<CityChooser.Items.Count;i++)
{
while( (i+1) < CityChooser.Items.Count && CityChooser.Items[i] ==
CityChooser.Items[i+1])
{
CityChooser.Items.RemoveAt(i+1);
}
}
dg_LocationSummary.DataBind();
}
But that didn't work either.
But got the same results if see my other post you can see why
"S. Justin Gengo" <sjg...@aboutfortunate.com> wrote in message
news:ewB$AMqWDH...@TK2MSFTNGP11.phx.gbl...
-Brian
"brian richards" <brian...@hotmail.com> wrote in message
news:u0Es8jpW...@TK2MSFTNGP10.phx.gbl...
Trying putting the whole select statement into the row filter.
ndv.RowFilter = "select distinct city from table where state = 'NC'";
--
S. Justin Gengo, MCP
Web Developer
Free code library at:
www.aboutfortunate.com
"Out of chaos comes order."
Nietzche
"brian richards" <brian...@hotmail.com> wrote in message
news:OutHBTqW...@TK2MSFTNGP12.phx.gbl...
public void BindGrid()
{
UpdateSelectStmt();
adptr_LocationSummary.Fill(dsLocationSummary1);
CityChooser.DataSource = dsLocationSummary1;
CityChooser.DataTextField = "City";
CityChooser.DataValueField = "City";
CityChooser.DataBind();
for(int i = 0;i<CityChooser.Items.Count;i++)
{
while( (i+1) < CityChooser.Items.Count && CityChooser.Items[i].Value ==
CityChooser.Items[i+1].Value)
{
CityChooser.Items.RemoveAt(i+1);
}
}
dg_LocationSummary.DataBind();
}
I wasn't comparing the values before. But this doesn't feel like a very
good solution. Meaning what about when I'm doing this for 8000 cities?
-Brian
"S. Justin Gengo" <sjg...@aboutfortunate.com> wrote in message
news:ewB$AMqWDH...@TK2MSFTNGP11.phx.gbl...
"brian richards" <brian...@hotmail.com> wrote in message
news:e1P83YqW...@TK2MSFTNGP11.phx.gbl...
Hope this helps.
JB
"brian richards" <brian...@hotmail.com> wrote in message news:<u0Es8jpW...@TK2MSFTNGP10.phx.gbl>...