protected void Page_Load(object sender, EventArgs e) {
ddlYear.DataSource = GetYear(); ddlYear.DataBind(); ddlYear.Items.Insert(0, "--Select--"); }

public static DataTable GetYear()
    {
        DataTable dt = new DataTable();
        string strcon = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        using (SqlConnection conn = new SqlConnection(strcon))
        {
            conn.Open();
            string strQuery = "SELECT Previous_Year AS Year FROM Year UNION ALL SELECT Current_Year FROM Year";
            SqlCommand cmd = new SqlCommand(strQuery, conn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(dt);
        }
        return dt;
    }

My datatable returns the below value

2014
2015

Now on page load my dropdown values should be like the below and by default I need to show 2014 value in the dropdown list.

--Select--
   All
  2014
  2015 

Related posts

Recent Viewed