Hi There,
Ive got an ASP .Net page with a listbox element.
This listbox element is databound to a sorted list filled with keys and
values from the database:
dbReader = lookupUtil.getL ookup("country" , 0, 0,
ConfigurationSe ttings.AppSetti ngs("DSN"))
If dbReader.HasRow s Then
countries = New SortedList
countries .Add("", "Please Select")
While dbReader.Read
countries .Add(CStr(dbRea der.GetInt32(0) ), dbReader.GetStr ing(1))
End While
End If
lstCountry.Data Source = countries
lstCountry.Data ValueField = "key"
lstCountry.Data TextField = "value"
lstCountry.Data Bind()
Im using a sortedlist because the documentation led me to believe that the
items will come out of the list int he same order that they went in (like an
array), but have key/value pairs to store both id's and values in the data
structure.
I know that the information is coming out ordered correctly from the DB, but
the listbox values are completely jumbled up.
Am i missing a setting for the SortedList as it seems to be behaving like a
HashTable at the moment.
Many Thanks.
Ben Mann. 2 1214
Why don't you just get back the values from the database, as you're
currently doing in the correct order, and bind that to your
dropdownlist/<select> element (I assume that's what lstCountry is).
Then you just insert a new listitem at position 0
lstCountry.Item s.Insert(0, New ListItem("Pleas e Select", ""))
Cheers
Ken
"Ben Mann" <be*****@btinte rnet.com> wrote in message
news:10******** *******@ersa.uk .clara.net...
: Hi There,
:
: Ive got an ASP .Net page with a listbox element.
: This listbox element is databound to a sorted list filled with keys and
: values from the database:
:
:
: dbReader = lookupUtil.getL ookup("country" , 0, 0,
: ConfigurationSe ttings.AppSetti ngs("DSN"))
: If dbReader.HasRow s Then
: countries = New SortedList
: countries .Add("", "Please Select")
: While dbReader.Read
: countries .Add(CStr(dbRea der.GetInt32(0) ), dbReader.GetStr ing(1))
: End While
: End If
:
:
: lstCountry.Data Source = countries
: lstCountry.Data ValueField = "key"
: lstCountry.Data TextField = "value"
: lstCountry.Data Bind()
:
:
: Im using a sortedlist because the documentation led me to believe that the
: items will come out of the list int he same order that they went in (like
an
: array), but have key/value pairs to store both id's and values in the data
: structure.
:
: I know that the information is coming out ordered correctly from the DB,
but
: the listbox values are completely jumbled up.
:
: Am i missing a setting for the SortedList as it seems to be behaving like
a
: HashTable at the moment.
:
: Many Thanks.
:
: Ben Mann.
:
:
Hi Ken
Thanks for that. It sounds like the right way to go.
But one extra question is....
Ive been thinking about storing the SortedList that ive been generating in
the Cache for an hour (or some other amount of time) to save querying the DB
on every page load. Is it feasable to do the same thing with a
SQLDataReader?
Thanks.
Ben Mann.
"Ken Schaefer" <ke*******@THIS adOpenStatic.co m> wrote in message
news:et******** ******@TK2MSFTN GP11.phx.gbl... Why don't you just get back the values from the database, as you're currently doing in the correct order, and bind that to your dropdownlist/<select> element (I assume that's what lstCountry is).
Then you just insert a new listitem at position 0
lstCountry.Item s.Insert(0, New ListItem("Pleas e Select", ""))
Cheers Ken
"Ben Mann" <be*****@btinte rnet.com> wrote in message news:10******** *******@ersa.uk .clara.net... : Hi There, : : Ive got an ASP .Net page with a listbox element. : This listbox element is databound to a sorted list filled with keys and : values from the database: : : : dbReader = lookupUtil.getL ookup("country" , 0, 0, : ConfigurationSe ttings.AppSetti ngs("DSN")) : If dbReader.HasRow s Then : countries = New SortedList : countries .Add("", "Please Select") : While dbReader.Read : countries .Add(CStr(dbRea der.GetInt32(0) ), dbReader.GetStr ing(1)) : End While : End If : : : lstCountry.Data Source = countries : lstCountry.Data ValueField = "key" : lstCountry.Data TextField = "value" : lstCountry.Data Bind() : : : Im using a sortedlist because the documentation led me to believe that
the : items will come out of the list int he same order that they went in
(like an : array), but have key/value pairs to store both id's and values in the
data : structure. : : I know that the information is coming out ordered correctly from the DB, but : the listbox values are completely jumbled up. : : Am i missing a setting for the SortedList as it seems to be behaving
like a : HashTable at the moment. : : Many Thanks. : : Ben Mann. : :
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kevin Swanson |
last post by:
I'm writing what should be a very simple app against an Oracle database. The
app has a number of user controls, any one of which is loaded into a main
display page using the loadControl method, depending on which menu item a
user selects. Each of these controls follows the same basic pattern: Get a
dataset from the database and then display the results using basic
databinding.
Everything works fine except that I'll occaisionally get an...
|
by: John Bailey |
last post by:
When I first built a few web pages in ASP .Net 2.0, I thought it was great.
The formview and detailview contorls would automatically layout the controls
for you, the update methods were automatically generated, and the
objectdatasource let you design against a business object through the gui.
Now I am working on my first real web application on 2.0, and I find this
automatic functionality doesn't do much beyond allowing me to generate...
|
by: GaryDean |
last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much
in answers so I'm reposting some questions posted by some of the programmers
here in our organization that never got answered...
In 1.1 we always did our own myDataAdapter.fills and we liked that control
for lots of good reasons. Now the new DataSource (or is it a
TableAdapter:Dataset) automatically fills the Gridview. How can we control
that fill?
In a...
|
by: Dirk |
last post by:
Hello,
I have a problem to use databinding with my business layer classes. My
data class does not have simple properties (string, int or datetime),
instead, all my properties are objects of the generic type Field<T>
(see sample code).
public class Employee
{
public Field<stringForename
|
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= |
last post by:
Hello to all,
I want to know if DataBinding in asp.net 2,0 is better than to fill up the
values of the controls of the following form:
this.miControlTextBox.Text = valorParaControlTextbox;
Performance with databinding is good in asp.net 2.0 ? Would you prefer:
databinding or set value to Text property of control ?
| |
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |