I'm trying to use LINQ and so I can bind it to an ASP.NET dropdown.
So far; this is what I have in terms of my LINQ expression; I'm new to LINQ, I started learning it this morning.
county.DataSource = (from taxUnit in TaxUnits.Descendants("CodeData")
join taxType in TaxTypes.Descendants("CodeData")
on
taxUnit.Attribute("taxuntype").Value
equals
taxType.Attribute("codeid").Value
where taxType.Attribute("taxuntypky").Value == "CO"
select new
{
County = taxUnit.Attribute("desc"),
CodeID = taxUnit.Attribute("codeid")
});
county.DataTextField = "desc";
county.DataValueField = "codeid";
county.DataBind();
Originally I was trying to convert it into a datatable; I've been informed you can actually do direct LINQ to DropDownList binding.
<asp:Label AssociatedControlID="county" runat="server">County</asp:Label>
<asp:DropDownList
ID="county"
runat="server" />
So far the result is... when I look at the dropdown box. Based on what I'm getting from LINQPad I expect
County CodeID
Willow County 1
CP2 TU 2
The only problem with the current answer is I have no idea how it works, thus I do not understand how to convert it to what I want.
I was previously able to use an ObjectDataSource that pointed to this method, and made a mock for List just to play with databinding.