Adds

Thursday 19 December 2013

Pass Parameter in C# DropDownList using Entity Framework

Method:



protected void LoadDropDownList(DropDownList ddl, object ds, string vf, string tf)
        {           
            ddl.DataSource = ds;
            ddl.DataValueField = vf;
            ddl.DataTextField = tf;
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem("--Select--", "0"));
        }
  

How to call this method:

LoadDropDownList(ddlRegion, r.GetAll(), "RegionID", "RegionName");