how to create a dynamic dropdownlist?

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2005
Posts: 41
Reputation: ohgosh is an unknown quantity at this point 
Solved Threads: 0
ohgosh's Avatar
ohgosh ohgosh is offline Offline
Light Poster

how to create a dynamic dropdownlist?

 
0
  #1
Dec 22nd, 2005
hi all,
do anyone knows how to create a dynamic dropdownlist? the dropdownlist will retrieve the list items from database..

eg: below is code for static dropdownlist where i declare the listitem myself.. but how should i declare listitem retreive from database?
  1. <asp:dropdownlist id="ddl" Runat="server">
  2. <asp:ListItem Value="1">A</asp:ListItem> <asp:ListItem Value="2">B</asp:ListItem> <asp:ListItem Value="3">C</asp:ListItem>
  3. </asp:dropdownlist>

thanks..
cheers,
ohgosh
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 483
Reputation: campkev is an unknown quantity at this point 
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: how to create a dynamic dropdownlist?

 
0
  #2
Dec 22nd, 2005
what kind of database are you using, SQL, access?
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 483
Reputation: campkev is an unknown quantity at this point 
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: how to create a dynamic dropdownlist?

 
0
  #3
Dec 22nd, 2005
if you can get the information out of the database and into a DataTable all you need to do is:
  1. DropDownList1.DataSource=dataTableName;
  2. DropDownList1.DataTextField="NameofDatabaseColumn";
  3. DropDownList1.DataValueField="NameofDatabaseColumn";
  4. DropDownList1.DataBind();

if you need help getting it from the database into the datatable let me know
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 41
Reputation: ohgosh is an unknown quantity at this point 
Solved Threads: 0
ohgosh's Avatar
ohgosh ohgosh is offline Offline
Light Poster

Re: how to create a dynamic dropdownlist?

 
0
  #4
Dec 23rd, 2005
Originally Posted by campkev
what kind of database are you using, SQL, access?
im using ms sql server 2000.. well, i will try the code later

thanks 4 ur help..
cheers,
ohgosh
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1
Reputation: sethu84 is an unknown quantity at this point 
Solved Threads: 0
sethu84 sethu84 is offline Offline
Newbie Poster

Re: how to create a dynamic dropdownlist?

 
0
  #5
Feb 17th, 2009
how to create an dynamic event handler for dropdownlist in c#
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2
Reputation: danidev is an unknown quantity at this point 
Solved Threads: 0
danidev danidev is offline Offline
Newbie Poster

Re: how to create a dynamic dropdownlist?

 
0
  #6
Mar 30th, 2009
See following to create dynamic dropdown list with event handler
http://urenjoy.blogspot.com/2009/03/...in-aspnet.html
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 370
Reputation: greeny_1984 is an unknown quantity at this point 
Solved Threads: 29
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz

Re: how to create a dynamic dropdownlist?

 
0
  #7
Mar 30th, 2009
hi,

check this code

  1. <asp:DropDownList ID="ddlist" runat="server" ></asp:DropDownList>
  2. protected void Page_Load(object sender, EventArgs e)
  3. {
  4.  
  5. if (!Page.IsPostBack)
  6. {
  7.  
  8. binddropdown();
  9.  
  10. }
  11. }
  12.  
  13.  
  14. public void binddropdown()
  15. {
  16. SqlConnection conn = new SqlConnection("Data Source='localhost';Initial Catalog='Northwind';Integrated Security=SSPI;Persist Security Info=False ");
  17. SqlDataAdapter da = new SqlDataAdapter("", conn);
  18. da.SelectCommand = new SqlCommand("select CategoryName,CategoryID from Categories", conn);
  19. DataSet ds = new DataSet();
  20. da.Fill(ds, "data");
  21. ddlist.AppendDataBoundItems = true;
  22. ListItem li = new ListItem();
  23. li.Text = "Select";
  24. li.Value = "Select";
  25. ddlist.Items.Add(li);
  26. ddlist.DataSource = ds.Tables[0].DefaultView;
  27. ddlist.DataTextField = "CategoryName";
  28. ddlist.DataValueField = "CategoryID";
  29. ddlist.DataBind();
  30.  
  31.  
  32.  
  33. }
If u r query is achieved,mark the thread as solved

Live and Let Live
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 1
Reputation: antonyvijayanv is an unknown quantity at this point 
Solved Threads: 0
antonyvijayanv antonyvijayanv is offline Offline
Newbie Poster

Re: how to create a dynamic dropdownlist? | Complete Solution

 
0
  #8
Apr 13th, 2009
To view Complete solution :

<URL SNIPPED, BROKEN LINK>

Thanks.
Last edited by peter_budo; Apr 15th, 2009 at 7:56 am. Reason: Please make sure that posted link is working
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 5
Reputation: mbaocha is an unknown quantity at this point 
Solved Threads: 0
mbaocha mbaocha is offline Offline
Newbie Poster

Re: how to create a dynamic dropdownlist?

 
0
  #9
Apr 20th, 2009
Which version of dot net are you using? I think creating a dynamic list box should be much of a difficult thing....
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC