Skip to main content

FillingDDl

private void FillDropDown()
{
string strConn = ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(strConn);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select CountryID, Country from Country";
DataSet objDs = new DataSet();
SqlDataAdapter dAdapter = new SqlDataAdapter();
dAdapter.SelectCommand = cmd;
con.Open();
dAdapter.Fill(objDs);
con.Close();
if (objDs.Tables[0].Rows.Count > 0)
{
ddlCountry.DataSource = objDs.Tables[0];
ddlCountry.DataTextField = "Country";
ddlCountry.DataValueField = "CountryID";
ddlCountry.DataBind();
ddlCountry.Items.Insert(0, "--Select--");
}
else
{
lblMsg.Text = "No Countries found";
}

}

Comments

Popular posts from this blog