adding data in drop down from database
-
Hi, For example, you can fill a Dataset using ADO.NET (Oledbconnection, OledbAdapter and Oledbcommand) and then set in the dropdown the property DataSource the dataset as value. Example of the dataset filling: //create the conn OleDbConnection con = new OleDbConection("conection string"); //create the command OleDbCommand cmd = new OleDbCommand("SELECT FROM ", con); //create the DataAdapter & DataSet OleDbDataAdapter da = new OleDbDataAdapter(cmd); DataSet ds = new DataSet(); //fill the DataSet da.Fill(ds);
-
SqlDataSource1.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["YourConnStr"].ConnectionString;//YourConnStr is initialized in web.config file SqlDataSource1.SelectCommand = "select * from yourtablename"; //Set SQL Command SqlDataSource1.DataSourceID = "SqlDataSource1";//Set DataSource ID, in this case DatasourceID is SqlDataSource1 SqlDataSource1.DataTextField = "ColText";//DataTextField represent text, which is displayed in DropDownList SqlDataSource1.DataValueField = "ColVal";";//DataValueField represent value SqlDataSource1.DataBind();
Hope this helps
"My advice to you is to get married. If you find a good wife, you will be happy; if not, you will become a philosopher." Socrates
-
Hi, For example, you can fill a Dataset using ADO.NET (Oledbconnection, OledbAdapter and Oledbcommand) and then set in the dropdown the property DataSource the dataset as value. Example of the dataset filling: //create the conn OleDbConnection con = new OleDbConection("conection string"); //create the command OleDbCommand cmd = new OleDbCommand("SELECT FROM ", con); //create the DataAdapter & DataSet OleDbDataAdapter da = new OleDbDataAdapter(cmd); DataSet ds = new DataSet(); //fill the DataSet da.Fill(ds);
-
SqlDataSource1.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["YourConnStr"].ConnectionString;//YourConnStr is initialized in web.config file SqlDataSource1.SelectCommand = "select * from yourtablename"; //Set SQL Command SqlDataSource1.DataSourceID = "SqlDataSource1";//Set DataSource ID, in this case DatasourceID is SqlDataSource1 SqlDataSource1.DataTextField = "ColText";//DataTextField represent text, which is displayed in DropDownList SqlDataSource1.DataValueField = "ColVal";";//DataValueField represent value SqlDataSource1.DataBind();
Hope this helps
"My advice to you is to get married. If you find a good wife, you will be happy; if not, you will become a philosopher." Socrates