DAL public class Dropdown { string _connstr = ConfigurationManager.ConnectionStrings["Connstr"].ConnectionString; public DataTable LoadAll() { DataTable table = new DataTable(); using (SqlConnection con = new SqlConnection(_connstr)) { string sql = "Select AutoId,FirstName from PersonDetails ORDER BY AutoId"; using (SqlCommand cmd = new SqlCommand(sql, con)) { using (SqlDataAdapter adp = new SqlDataAdapter(cmd)) { adp.Fill(table); } } } return table; } } BAL public DataTable LoadAll() { DropDownList1.DAL.Dropdown drop = new Dropdown(); return drop.LoadAll(); } MainWebPage(.aspx) //set the columname which u want to find as DataTextField and Primarykey or Autoincrement column as DataValueField for the dropdownlist <asp:DropDownList ID="dropdown1" runat="server" DataValueField="AutoId" DataTextField="FirstName"></asp:DropDownList> code behind(.cs) protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { LoadAllData(); } } private void LoadAllData() { DropDownList1.BAL.Class1 drop = new Class1(); dropdown1.DataSource = drop.LoadAll(); dropdown1.DataBind(); }
Login to post response