protected void Page_Load(object sender, EventArgs e)
{
BindDropDown(ddl1, "SP_1", "textfield", "valuefield");
BindDropDown(ddl2, "SP_2", "textfield", "valuefield");
}
private void BindDropDown(DropDownList dl, string spName, string dataTextField, string dataValueField)
{
SqlConnection _cn = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["behtopConnectionString"].ConnectionString);
SqlCommand _cmd = new SqlCommand(spName, _cn);
_cmd.CommandType = CommandType.StoredProcedure;
_cn.Open();
SqlDataReader _dr = _cmd.ExecuteReader();
if (_dr.HasRows)
{
dl.DataSource = _dr;
dl.DataTextField = dataTextField;
dl.DataValueField = dataValueField;
dl.DataBind();
}
_cn.Close();
}