Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am getting proper and accurate data in ddl from database.

What I have tried:

protected void Page_Load(object sender, EventArgs e)
       {
           if (!IsPostBack)
           {
               string myQuery = "select * from studentDetail";
               cmd = new SqlCommand(myQuery, conn);
               cmd.Connection = conn;
               SqlDataAdapter sda = new SqlDataAdapter();
               sda.SelectCommand = cmd;
               DataSet ds = new DataSet();
               sda.Fill(ds);
               GridView1.DataSource = ds;
               GridView1.DataBind();
               int hasRows = ds.Tables[0].Rows.Count;
               int c = 0;
               if(c< hasRows){
                   DropDownList1.Items.Add(ds.Tables[0].Rows[c]["rollnum"].ToString());
                   c++;
               }
               conn.Close();


           }
       }
Posted
Updated 27-Jan-19 9:36am

1 solution

I would have a look at this c# - What is the right way to populate a DropDownList from a database? - Stack Overflow[^]

I would also change your select statement to return only the columns that you need also.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900