473,386 Members | 1,779 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,386 software developers and data experts.

DropDownList only appearing once

I guess my problem begs the question, how do I store a DropDownList (or other control in Application State and pull it out and reuse it? In my web application Global.asax.cs I am creating a DropDownList and throwing it into Application state, hoping to reuse it on this page (and wherever else). This code should dynamically create a table with 3 rows and a ddl0 for each. It only creates one DDL and displays it in the 3rd row, very strange.

Expand|Select|Wrap|Line Numbers
  1.             protected override void OnInit(EventArgs e)
  2.             {
  3.                 sSearchConditions = new string[] { "", "Begins With", "Contains", "Does Not Contain", "Ends With", "Equals", "Not Equal" };
  4.                 base.OnInit(e);
  5.                 Table tSearch = new Table();
  6.                 tSearch.ID = "tCriteria";
  7.                 TableHeaderRow thr = new TableHeaderRow();
  8.  
  9.                 for (int n = 0; n < 3; n++)
  10.                 {
  11.                     Label lblFields = new Label();
  12.                     lblFields.Text = "Select Search Field:";
  13.                     lblFields.CssClass = "tLBLText";
  14.                     Label lblCondition = new Label();
  15.                     lblCondition.Text = "Select Condition: ";
  16.                     lblCondition.CssClass = "tLBLText";
  17.                     Label lblValue = new Label();
  18.                     lblValue.Text = "Type Value: ";
  19.                     lblValue.CssClass = "tLBLText";
  20.  
  21.                     //Fields
  22.                     DropDownList ddl0 = new DropDownList();
  23.                     ddl0 = (DropDownList)Application[Global.DDLFields];
  24.                     ddl0.ID = "ddlFields" + n.ToString();
  25.                     //Conditions
  26.                     DropDownList ddl1 = new DropDownList();
  27.                     ddl1.ID = "ddlCondition" + n.ToString();
  28.                     ddl1.DataSource = sSearchConditions;
  29.                     ddl1.DataBind();
  30.  
  31.                     TextBox tb1 = new TextBox();
  32.                     tb1.ID = "tb" + n.ToString();
  33.                     tb1.CssClass = "tcText";
  34.                     TableRow tr = new TableRow();
  35.  
  36.                     TableCell tc1 = new TableCell();
  37.                     tc1.Controls.Add(lblFields);
  38.                     tc1.Controls.Add(ddl0);
  39.  
  40.                     TableCell tc2 = new TableCell();
  41.                     tc2.Controls.Add(lblCondition);
  42.                     tc2.Controls.Add(ddl1);
  43.  
  44.                     TableCell tc3 = new TableCell();
  45.                     tc3.Controls.Add(lblValue);
  46.                     tc3.Controls.Add(tb1);
  47.                     tr.Cells.Add(tc1);
  48.                     tr.Cells.Add(tc2);
  49.                     tr.Cells.Add(tc3);
  50.                     tSearch.Rows.Add(tr);
  51.                 }
  52.                 pCustomSearch.Controls.Add(tSearch);
  53.                 //pCustomSearch is a Panel Control
  54.  
May 28 '09 #1
4 1217
balame2004
142 100+
Code you have given works perfectly. Could you please give me code to define DDLFields so I can able to reproduce the issue.
May 29 '09 #2
Frinavale
9,735 Expert Mod 8TB
@stoogots2
You shouldn't be storing the a page level control in the Application State.

The Global.asax is used to mange application level objects like Session (not the objects within Session but Session itself...it handles the Events that Session raises like Session_Start and Session_End).

Controls like DropDownLists are page level controls, not application level controls. They exist on a page and the page code manages them. The page listen for, and handles events that these controls raise...

Instead of trying to store the DropDownList like you are, you should consider using the Global.asax to create/destroy a cached version data source that you can use with the page level controls.

Or you could create a UserControl that can be used on any page that you require.

What exactly are you trying to do before I start recommending 100 different ways to solve your problem?
May 29 '09 #3
I switched things around last week, but I was trying to reuse a DropDownList as it appears in several places throughout the application. I realize that I could've utilized the Global.asax.cs (which I actually use) to store the datasource, but I thought it would be "niftier" if I could bind the data to the DropDownList and store, and reuse that whenever I need it (and not having to call DataBind). If you guys know a good way to do this, and have the time, I would love to learn.

Thanks,
Jun 4 '09 #4
Frinavale
9,735 Expert Mod 8TB
Is it just the DropDownList or are there other controls that go with the DropDownList to make something work?

Check out user controls :)
Jun 4 '09 #5

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

Similar topics

2
by: Shiju Poyilil | last post by:
Hello, I have a datagrid with only one row and its having 2 dropdownlists, I need to populate the secodn dropdownlist on the basis of the selection in the first dropdown. but I am not able to...
2
by: Dave | last post by:
Hi, I'm building a maintenance form for a table and some of the fields are textboxes (i.e name) and some should be dropdowns (i.e country of origin) When a user clicks 'Edit' in the...
5
by: dhnriverside | last post by:
Hi I'm using a DataReader to pull items into a DropDownList from an SQL database. Everything works fine, but my client has started to nice that newly added database entries aren't appearing in...
0
by: Mutley | last post by:
I am finding an issue with the current DropDownList and ListBox ASP.NET Web Controls. I had a system set up for Arabic and a string that I put into a drop down contained a number. The letters were...
0
by: Dewey | last post by:
I have a datagrid with a footer that has a dropdownlist. I am able to bind the datagrid to a dataset just fine. But I also want to add a listitem that says "-- choose --" to the top of the list. ...
0
by: Stimp | last post by:
As rows in a datalist are being output, I have a dropdownlist appearing on each row, being populated as the datalist is generated. I tried to use Dropdownlist.Databind in the...
3
by: Jon Paal | last post by:
this text keeps showing up in my gridview dropdownlist "System.Data.DataRowView" How do I prevent this problem ?
8
by: Cirene | last post by:
I have a dropdownlist that is bound to a query. Is it possible to further filter the items after the fact? The dropdownlist is inside a...
0
by: Nathan Sokalski | last post by:
I have a DropDownList in which I set the SelectedIndex property in my code. However, when I run a debug it does not appear selected (actually, none of the ListItems are even visible in the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.