Click here to Skip to main content
Sign Up to vote bad
good
See more: C#ASP.NET
 

  SqlCommand cmd = new SqlCommand("select * from user_login where groupid=1", cnn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
 

            ddlstudentname.DataTextField="name";
            ddlstudentname.DataBind();
 
i have to fill dropdown list with name ( name comming from query).but this coding not working.Not give error.what is problem.
Posted 8 Jan '13 - 23:55


2 solutions

Hi,
 
your not assign the DataSet to your DropDownList.
 
Please try this
 

 
  SqlCommand cmd = new SqlCommand("select * from user_login where groupid=1", cnn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            ddlstudentname.DataSource=ds;
            ddlstudentname.DataTextField="name";
            ddlstudentname.DataVlaueField="name";
            ddlstudentname.DataBind();
 
  Permalink  
Comments
Member 9511889 - 11 Jan '13 - 2:11
how to add new item in dropdown using query?
See Below code.
Bold Case is newly added line.
    SqlCommand cmd = new SqlCommand("select * from user_login where groupid=1", cnn);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    da.Fill(ds);
    
    ddlstudentname.DataSource=ds;
    ddlstudentname.DataVlaueField="name";
    ddlstudentname.DataTextField="name";
 
    ddlstudentname.DataBind();
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 355
1 Sergey Alexandrovich Kryukov 338
2 Arun Vasu 315
3 Maciej Los 208
4 Aarti Meswania 180
0 Sergey Alexandrovich Kryukov 9,755
1 OriginalGriff 7,549
2 CPallini 4,018
3 Rohan Leuva 3,362
4 Maciej Los 2,951


Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid