How to add Text to DropDownList when populating from Database using Dataset
How to hide TabControls Tabpages on load
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Prabhu RajaRank #861 · 2.6K reputationPosted Sep 11, 2011, 3:32 AM EDT
add dropdownlist like this,
SqlConnection con = new SqlConnection(" Your Database Connection String Here" );
try
{
con.Open();
Dataset ds = new Dataset();
SqlDataAdapter da = new SqlDataAdapter("Select * from sys.tables",con);
da.fill ( ds, da.Tables[0]);
DropDownList1.DataTextField = ds.Tables(0).Columns(1).Caption
DropDownList1.DataValueField = ds.Tables(0).Columns(0).Caption
DropDownList1.DataSource = ds.Tables(0)
DropDownList1.DataBind()
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
Hide you Tab Control By using :
private void Form1_Load(object sender, System.EventArgs e)
{
if ( (tabControl1.SelectedTab == tabPage1))
{
tabControl1.Remove(tabPage2);
}
else if ((tabControl1.SelectedTab == tabPage2))
{
tabControl1.Remove(tabPage1);
}
}
Or try this Link :
------------------------------------------------
If it helps you, then mark as "Correct Answer"
Satyapriya NayakRank #47 · 31.5K reputationPosted Sep 11, 2011, 4:41 AM EDT
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "Select * from area";
SqlCommand com = new SqlCommand(str, con);
SqlDataAdapter sqlda = new SqlDataAdapter(com);
DataSet ds = new DataSet();
sqlda.Fill(ds, "area");
DropDownList1.DataTextField = "country";
DropDownList1.DataValueField = "state";
DropDownList1.DataSource = ds;
DropDownList1.DataMember = "area";
DropDownList1.DataBind();
con.Close();
Note:- //DataTextField is used for the user to bind data to dropdownlist and DataValueField is used like key//
Thanks
If this post helps you mark it as answer