Click here to Skip to main content
12,078,259 members (45,636 online)
Rate this:
 
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 9-Jan-13 0:55am
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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web03 | 2.8.160212.1 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2016
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