Wrox Programmer Forums
|
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 10th, 2009, 10:01 PM
Authorized User
 
Join Date: Dec 2007
Posts: 59
Thanks: 9
Thanked 0 Times in 0 Posts
Post dropdownlist

Hello everyone
Please guide me how to create dropdownlist when i want it show 3 dropdownlist
EX.
I input the number 3 into textbox.
and then it show 3 dropdownlist.
that mean amount of dropdownlist depending on the number on textbox.
Thanks
Regards
Phuc Hoang
 
Old March 10th, 2009, 10:53 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Depends. Do you want to do this client side or server side? Is there a button involved or is this some sort of AJAX that is fired off when the Textbox value changes?

Since you posted in the ASP.NET forum I will assume you want to do this server side so some code like the following would work:

csharp Code:
for(int i = 0; i < Convert.ToInt32(textBox1.Text); i++)
{
  ListItem item = new ListItem("someText", "someValue");
  DropDownList1.Items.Add(item);
}

Obviously there is no error checking in this code to check to make sure that a whole number was passed in and not, say, a string but you should get the idea.

hth.
-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
 
Old March 11th, 2009, 04:40 AM
Authorized User
 
Join Date: Dec 2007
Posts: 59
Thanks: 9
Thanked 0 Times in 0 Posts
Post

Quote:
Originally Posted by dparsons View Post
Depends. Do you want to do this client side or server side? Is there a button involved or is this some sort of AJAX that is fired off when the Textbox value changes?

Since you posted in the ASP.NET forum I will assume you want to do this server side so some code like the following would work:

csharp Code:
for(int i = 0; i < Convert.ToInt32(textBox1.Text); i++)
{
  ListItem item = new ListItem("someText", "someValue");
  DropDownList1.Items.Add(item);
}

Obviously there is no error checking in this code to check to make sure that a whole number was passed in and not, say, a string but you should get the idea.

hth.
-Doug
Thanks so much for helping me to do that





Similar Threads
Thread Thread Starter Forum Replies Last Post
dropdownlist sumith ASP.NET 1.0 and 1.1 Professional 1 February 23rd, 2007 09:11 AM
DropdownList Venkatesan ASP.NET 1.0 and 1.1 Basics 1 December 11th, 2006 11:03 AM
how to get value from dropdownlist vandat ASP.NET 1.0 and 1.1 Basics 3 November 28th, 2005 12:47 AM
DropDownList chiraagb VS.NET 2002/2003 5 June 15th, 2004 03:12 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.