Click here to Skip to main content
11,634,827 members (74,649 online)
Rate this: bad
good
Please Sign up or sign in to vote.
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:55pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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  
v2
Comments
Member 9511889 at 11-Jan-13 2:11am
   
how to add new item in dropdown using query?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
0 OriginalGriff 8,736
1 Sergey Alexandrovich Kryukov 8,419
2 Mika Wendelius 6,845
3 F-ES Sitecore 2,354
4 Suvendu Shekhar Giri 2,205


Advertise | Privacy | Mobile
Web02 | 2.8.150728.1 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100