473,396 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

.net(dynamic dropdownlist)

sir,
i have a dynamic drop downlist. I have to get the data from the database. but i am not able to do it .the code which i have used for dynamic dropdownlist is
Expand|Select|Wrap|Line Numbers
  1. for(int i = 0; i <= count; i++)
  2.        {
  3.             DropDownList  t = new DropDownList();
  4.             t.ID = "C" + i;
  5.  
  6.             Literal l1 = new Literal();
  7.             l1.Text = "<br/>";
  8.                      PlaceHolder1.Controls.Add(t);
  9.  
  10.                      PlaceHolder1.Controls.Add(l1);
  11.  
  12.  
  13.        }
Sep 17 '08 #1
3 1314
cloud255
427 Expert 256MB
Are you trying to create a new dropdown box control for each record from your database? That is what your code is doing, by saying:

Expand|Select|Wrap|Line Numbers
  1. for(int i = 0; i <= count; i++)
  2. {
  3. DropDownList t = new DropDownList();
  4.  .....
you try to create as many dropDownLists as there are count (which i am assuming is your number of records), but this is not happening as you are just using the same variable, t, and thus re-initilizing it many times...

if you want one control with all the records in the list, you need to move the decleration of the dropDownList outside of the for loop:

Expand|Select|Wrap|Line Numbers
  1. DropDownList t = new DropDownList();
  2.  
  3. for(int i = 0; i <= count; i++)
  4. {
and then add objects to the Items collection of the DropDownList.
Sep 17 '08 #2
Frinavale
9,735 Expert Mod 8TB
Aside from the facts that Cloud has pointed out...the scope of your DropDownLists are incorrect.

They will get added to the page but you will not be able to retrieve anything from these DropDownList when the page is posted back.

See this article on how to use dynamic controls in asp.net for more information on what I'm talking about.

-Frinny
Sep 17 '08 #3
Frinavale
9,735 Expert Mod 8TB
Please at least attempt to understand the concepts outlined by the dynamic controls article. I realize that it is written in VB.NET but these same concepts are applied in all ASP.NET applications......only the syntax differs.

What confused you in the article? Just the VB code?

-Frinny
Sep 18 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Corey | last post by:
I'm trying to finish off do an ASP.NET project where a DropDownList box is used to access a Table. Once you Make a selection on an item in the DropDownListBox, it updates a DataView, and text...
2
by: Rob Rogers | last post by:
I am old programmer, but this asp.net stuff throws me for a loop. I have an asp.net page that I need to create a dynamic hyperlink from based on the user selection from the drop down list and...
1
by: Micheal | last post by:
I have an ASP.NET website using C# that has a Web Control DropDownList. The DropDownList is filled by a database call to SQL Server. The problem is that when I click to change what is selected...
5
by: Lucas Tam | last post by:
Hi all, I have a DropDownList on my page created in Design Time calledddlDate. In code, I do the following: 1 ddlDate = New DropDownList() <- To Clear the drop down list 2...
4
by: Bishop | last post by:
I have a number of simple select queries that a user needs to be able to execute and display the data on the screen in a gridview. My thought was that I could use a Gridview set to dymanically...
11
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
1
by: Santosh | last post by:
Dear all, i am giving selection to the user like when it select country from asp.net dropdownlist it will display all records in next dropdownlist related to it on asp.net...
2
by: Max2006 | last post by:
Hi, I can see ASP.NET MVC and ASP.NET Dynamic Data extensions are not tagged as beta anymore here: http://www.asp.net/downloads/ Does this mean that we have the final release and we can...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.