/////////////////////
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindContrydropdown();
}
}
///
/// Bind COuntrydropdown
///
protected void BindContrydropdown()
{
//conenction path for database
using (SqlConnection con = new SqlConnection("Data Source=localhost\sqlexpress;Integrated Security=true;Initial Catalog=Mfwamba"))
{
con.Open();
SqlCommand cmd = new SqlCommand("Select UserId,UserName FROM UserInformation", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
ddlCountry.DataSource = ds;
ddlCountry.DataTextField = "UserName";
ddlCountry.DataValueField = "UserId";
ddlCountry.DataBind();
ddlCountry.Items.Insert(0, new ListItem("--Select--", "0"));
con.Close();
}
}
Jignesh TrivediPosted Jul 16, 2013, 11:07 PM
are you getting any error on above code?
Iftikar HussainPosted Jul 16, 2013, 11:50 AM
Try like this
Iftikar