944,059 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 39502
  • ASP.NET RSS
Dec 22nd, 2005
0

how to create a dynamic dropdownlist?

Expand Post »
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?
ASP.NET Syntax (Toggle Plain Text)
  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..
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
ohgosh is offline Offline
41 posts
since Jul 2005
Dec 22nd, 2005
0

Re: how to create a dynamic dropdownlist?

what kind of database are you using, SQL, access?
Reputation Points: 14
Solved Threads: 19
Posting Pro in Training
campkev is offline Offline
484 posts
since Jul 2005
Dec 22nd, 2005
0

Re: how to create a dynamic dropdownlist?

if you can get the information out of the database and into a DataTable all you need to do is:
ASP.NET Syntax (Toggle Plain Text)
  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
Reputation Points: 14
Solved Threads: 19
Posting Pro in Training
campkev is offline Offline
484 posts
since Jul 2005
Dec 23rd, 2005
0

Re: how to create a dynamic dropdownlist?

Quote 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..
Reputation Points: 10
Solved Threads: 0
Light Poster
ohgosh is offline Offline
41 posts
since Jul 2005
Feb 17th, 2009
0

Re: how to create a dynamic dropdownlist?

how to create an dynamic event handler for dropdownlist in c#
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sethu84 is offline Offline
1 posts
since Sep 2008
Mar 30th, 2009
0

Re: how to create a dynamic dropdownlist?

See following to create dynamic dropdown list with event handler
http://urenjoy.blogspot.com/2009/03/...in-aspnet.html
Reputation Points: 10
Solved Threads: 0
Newbie Poster
danidev is offline Offline
2 posts
since Oct 2008
Mar 30th, 2009
0

Re: how to create a dynamic dropdownlist?

hi,

check this code

ASP.NET Syntax (Toggle Plain Text)
  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. }
Reputation Points: 25
Solved Threads: 29
Posting Whiz
greeny_1984 is offline Offline
372 posts
since Apr 2007
Apr 13th, 2009
0

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

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
antonyvijayanv is offline Offline
1 posts
since Apr 2009
Apr 20th, 2009
0

Re: how to create a dynamic dropdownlist?

Which version of dot net are you using? I think creating a dynamic list box should be much of a difficult thing....
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mbaocha is offline Offline
5 posts
since Apr 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Asp.net behind code not correct
Next Thread in ASP.NET Forum Timeline: Pass Windows User (domain\userid) to report url in ASCX page





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC