To populate dropdown list

To populate dropdown list from data base

TO populatwe dropdown list the following code snippet will be as follows,
firstly i have established the sql connection globally and the same thing follows for SqldataAdapter and DataSet as well and was used when needed,the SqldataAdapter was used as a bridge between DataSet and the server,The DataSet was mainly used to get the element from data base it is as follows(DataSet<-DataAdapter<-DataProvider<-Database).In the pager load event I have established the sqlConnection and the select query was performed in the dataAdapter and was retrived in DataSet through DA.Fillhere i have used an intermediate tabe to store the data temporarily and the dropdown list was populated as shown below


public partial class Default3 : System.Web.UI.Page
string connection = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlDataAdapter DA= new SqlDataAdapter();
DataSet DS = new DataSet();

protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
SqlConnection con = new SqlConnection(connection);
DA = new SqlDataAdapter("select * from Category1",con);
DS = new DataSet();
DropDownList1.DataSource = DS.Tables[0];
DropDownList1.DataTextField = DS.Tables[0].Columns["CategoryName"].ColumnName.ToString();
DropDownList1.DataValueField = DS.Tables[0].Columns["CategoryID"].ColumnName.ToString();



No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: