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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Sep 11, 2011, 8:41 AM
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
Prabhu RajaPosted Sep 11, 2011, 7:32 AM
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"