Pages

Saturday, November 30, 2013

How to bind LINQ data to dropdownlist (TEXT,VALUE)


Let's assume we have a Web Service which will return the results as an
object with the values DDLTEXT
and
DDLVALUE.
The following will explain how to use LINQ to query and then bind the results to the

DropDownList:
  DataTextField and  DataValueField

ddl.DataSource = wsMethod.Contents.OrderBy(o=>o.DDLTEXT);

//specify result object values
ddl.DataTextField = "DDLTEXT";
ddl.DataValueField = "DDLVALUE";

ddl.DataBind();