//in page load
BindDropdownList("select * from tbldate",ddlDate,"date","dateid","select date");
BindDropdownList("select * from tblmonth",ddlDate,"month","monthid","select Month");
BindDropdownList("select * from tblYear",ddlYear,"Year","Yearid","select Year");
//To Bind DropdownList
public DropDownList BindDropdownList(string qryInput, DropDownList dropdownId, string dataTextField, string dataValueField, string zerothIndexField)
{
try
{
con = OpenConnection();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = qryInput;
dropdownId.DataSource = cmd.ExecuteReader();
dropdownId.DataTextField = dataTextField;
dropdownId.DataValueField = dataValueField;
dropdownId.DataBind();
dropdownId.Items.Insert(0, zerothIndexField);
CloseConnection();
return dropdownId;
}
catch (Exception ex)
{
throw ex;
}
}