protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT EmpId, Name FROM tblEmployee"))
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
ddlEmployee.DataSource = cmd.ExecuteReader();
ddlEmployee.DataTextField = "Name";
ddlEmployee.DataValueField = "EmpId";
ddlEmployee.DataBind();
con.Close();
}
}
ddlEmployee.Items.Insert(0, new ListItem("--Select Employee--", "0"));
}
}