views:

14

answers:

1

I am new to Linq and trying to get a handle on how to bind a drop down to a SQL user defined function.

            //Populate the Pledge dropdown
        var db = new App_Data.MyDBDataContext();
        int? partnerID = Convert.ToInt32(Request.QueryString["PartnerID"]);

        var pledges =
            from p in db.ufn_AvailablePledgesByPartner(partnerID)
            select new
            {
                PledgeAndPartnerName = p.PledgeAndPartnerName,
                PledgeID = p.PledgeID
            };

        DropDownList ddlPledgeID = (DropDownList)DetailsViewContribution.FindControl("DropDownListPledgeID");
        ddlPledgeID.DataSource = pledges;
        ddlPledgeID.DataTextField = pledges.PledgeAndPartnerName;
        ddlPledgeID.DataValueField = pledges.PledgeID;

The current problem is the last 2 lines where I'm trying to reference properties of the anonymous class. "'System.Linq.IQueryable' does not contain a definition for 'PledgeAndPartnerName' and no extension method..." I naively thought the compiler was supposed to figure this out, but obviously I'm assuming C# is now more dynamic than it really is.

Thanks for any input.

A: 

Try this:

ddlPledgeID.DataTextField = "PledgeAndPartnerName";
ddlPledgeID.DataValueField = "PledgeID";
Dave Markle
Thank you. I ended up implementing your suggestion, but in the markup.
Will