views:

88

answers:

3
<data>
<food>
<id>1</id>
<name>asparagus</name>
<catlog>7190</catlog>
</food>
<food>
<id>2</id>
<name>almonds</name>
<catlog>7190</catlog>
</food>
<food>
<id>3</id>
<name>asparagus</name>
<catlog>7192</catlog>
</food>
<food>
<id>4</id>
<name>asparagus</name>
<catlog>7193</catlog>
</food>
</data>

i would like to get the unique catlogs, so from this list i want to extract only 7190, 7192, and 7193. i have a script that puts it into a dropdownlist by using:

DropDownList1.DataSource = dv
        DropDownList1.DataBind()

but i need it to get only the unique values.

+2  A: 

Take a look at LINQ to XML! With this you have the power to directly query a blob of xml but with less headache than using XPATH (which you could also use to do the same task).

Then you could point your datasource at the result from the LINQ query over your XML blob.

Andrew Siemer
hey can u walk me through it please i am beginner with asp.net
I__
A: 

Try the following

Public Function Unique(ByVal doc As XDocument) As IEnumerable(Of String)
  Return doc...<catalog>.Select(Function(x) CType(x,Integer)).Distinct()
End Function

Quick Note: The CType may seem strange at first but it does work because the XElement class defines an explicit conversion operator for many value types including Integer.

JaredPar
hey can you show me in vb?
I__
@alex, that is VB
JaredPar
A: 

LINQ is the prefered way I think, but an another option is :

Dim newTable As DataTable = dataView.ToTable( True, "Category")
DropDownList1.DataSource = newTable 
DropDownList1.DataBind()
Canavar
please recommend an example LINQ script ive never used it!
I__