Click here to Skip to main content
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);
 
<pre>
        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 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);
 
<pre>
<b><u>ddlstudentname.DataSource=ds;</u></b>
<b><u>ddlstudentname.DataVlaueField="name";</u></b>
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 490
1 Sergey Alexandrovich Kryukov 395
2 Maciej Los 285
3 ProgramFOX 265
4 CHill60 200
0 OriginalGriff 490
1 Sergey Alexandrovich Kryukov 395
2 Maciej Los 285
3 ProgramFOX 265
4 CHill60 200


Advertise | Privacy | Mobile
Web01 | 2.8.150331.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