Can you databind a dropdownlist to another dropdownlist?
I have 2 identical list. I am getting my data from a DataReader, so as soon
as I have bound the first DDL, I can't do it again to the next as the
dataReader can only be read once.
I tried:
ExperienceLevel .DataSource=dbR eader
ExperienceLevel .DataTextField= "Descriptio n"
ExperienceLevel .DataValueField ="ExperienceLev elID"
ExperienceLevel .databind()
ExperienceLevel .Items.Insert(0 , "Select Experience Level")
ExperienceLevel .Items(0).value = 0
ActualExperienc eLevel.DataSour ce=ExperienceLe vel
ActualExperienc eLevel.DataText Field= DataTextField
ActualExperienc eLevel.DataValu eField=DataValu eField
ActualExperienc eLevel.databind ()
ActualExperienc eLevel.Items.In sert(0, "Select Experience Level")
ActualExperienc eLevel.Items(0) .value = 0
But that doesn't seem to work.
Thanks,
Tom 8 1666
Fill an ArrayList with DictionaryEntri es, then bind to that.
Example
ArrayList arlItems = new ArrayList ();
while (dReader.Read ())
arlItem.Add (new DictionaryEntry (dReader["Descriptio n"].ToString (),
dReader["ExperienceLeve lID].ToString());
then create an array and set the datasources
ActualExperienc eLevel.DataSour ce = arrDEntries;
ActualExperienc eLevel.DataText Field = "value";
ActualExperienc eLevel.DataValu eField = "key";
Hope this helps,
Brendan
To bind to a dropdownlist the datasource must implement IListSource or
IEnumerable. DropDownList.It ems is enumerable.
So this will work:
ExperienceLevel .DataSource=dbR eader
ExperienceLevel .DataTextField= "Descriptio n"
ExperienceLevel .DataValueField ="ExperienceLev elID"
ExperienceLevel .DataBind()
ExperienceLevel .Items.Insert(0 , "Select Experience Level")
ExperienceLevel .Items(0).value = 0
ActualExperienc eLevel.DataSour ce=ExperienceLe vel.Items
ActualExperienc eLevel.DataBind ()
Don't add your default item because it is already in the list.
Tim
"tshad" wrote: Can you databind a dropdownlist to another dropdownlist?
I have 2 identical list. I am getting my data from a DataReader, so as soon as I have bound the first DDL, I can't do it again to the next as the dataReader can only be read once.
I tried:
ExperienceLevel .DataSource=dbR eader ExperienceLevel .DataTextField= "Descriptio n" ExperienceLevel .DataValueField ="ExperienceLev elID" ExperienceLevel .databind() ExperienceLevel .Items.Insert(0 , "Select Experience Level") ExperienceLevel .Items(0).value = 0
ActualExperienc eLevel.DataSour ce=ExperienceLe vel ActualExperienc eLevel.DataText Field= DataTextField ActualExperienc eLevel.DataValu eField=DataValu eField ActualExperienc eLevel.databind () ActualExperienc eLevel.Items.In sert(0, "Select Experience Level") ActualExperienc eLevel.Items(0) .value = 0
But that doesn't seem to work.
Thanks,
Tom
"timkling" <ti******@discu ssions.microsof t.com> wrote in message
news:D8******** *************** ***********@mic rosoft.com... To bind to a dropdownlist the datasource must implement IListSource or IEnumerable. DropDownList.It ems is enumerable.
So this will work: ExperienceLevel .DataSource=dbR eader ExperienceLevel .DataTextField= "Descriptio n" ExperienceLevel .DataValueField ="ExperienceLev elID" ExperienceLevel .DataBind() ExperienceLevel .Items.Insert(0 , "Select Experience Level") ExperienceLevel .Items(0).value = 0
ActualExperienc eLevel.DataSour ce=ExperienceLe vel.Items ActualExperienc eLevel.DataBind ()
Worked great.
Don't add your default item because it is already in the list.
Which default item - the insert?
ExperienceLevel .Items.Insert(0 , "Select Experience Level")
Thanks,
Tom Tim
"tshad" wrote:
Can you databind a dropdownlist to another dropdownlist?
I have 2 identical list. I am getting my data from a DataReader, so as soon as I have bound the first DDL, I can't do it again to the next as the dataReader can only be read once.
I tried:
ExperienceLevel .DataSource=dbR eader ExperienceLevel .DataTextField= "Descriptio n" ExperienceLevel .DataValueField ="ExperienceLev elID" ExperienceLevel .databind() ExperienceLevel .Items.Insert(0 , "Select Experience Level") ExperienceLevel .Items(0).value = 0
ActualExperienc eLevel.DataSour ce=ExperienceLe vel ActualExperienc eLevel.DataText Field= DataTextField ActualExperienc eLevel.DataValu eField=DataValu eField ActualExperienc eLevel.databind () ActualExperienc eLevel.Items.In sert(0, "Select Experience Level") ActualExperienc eLevel.Items(0) .value = 0
But that doesn't seem to work.
Thanks,
Tom
a datareader can not be used twice, because it forward only cursor. the
second databind will find itself at the end.
-- bruce (sqlwork.com)
"tshad" <ts**********@f tsolutions.com> wrote in message
news:OY******** ******@TK2MSFTN GP14.phx.gbl... Can you databind a dropdownlist to another dropdownlist?
I have 2 identical list. I am getting my data from a DataReader, so as soon as I have bound the first DDL, I can't do it again to the next as the dataReader can only be read once.
I tried:
ExperienceLevel .DataSource=dbR eader ExperienceLevel .DataTextField= "Descriptio n" ExperienceLevel .DataValueField ="ExperienceLev elID" ExperienceLevel .databind() ExperienceLevel .Items.Insert(0 , "Select Experience Level") ExperienceLevel .Items(0).value = 0
ActualExperienc eLevel.DataSour ce=ExperienceLe vel ActualExperienc eLevel.DataText Field= DataTextField ActualExperienc eLevel.DataValu eField=DataValu eField ActualExperienc eLevel.databind () ActualExperienc eLevel.Items.In sert(0, "Select Experience Level") ActualExperienc eLevel.Items(0) .value = 0
But that doesn't seem to work.
Thanks,
Tom
> Which default item - the insert? ExperienceLevel .Items.Insert(0 , "Select Experience Level")
Yes. Do it to the first list, but after that it will be in the second list
automatically.
Tim
"tshad" wrote:
"timkling" <ti******@discu ssions.microsof t.com> wrote in message news:D8******** *************** ***********@mic rosoft.com... To bind to a dropdownlist the datasource must implement IListSource or IEnumerable. DropDownList.It ems is enumerable.
So this will work: ExperienceLevel .DataSource=dbR eader ExperienceLevel .DataTextField= "Descriptio n" ExperienceLevel .DataValueField ="ExperienceLev elID" ExperienceLevel .DataBind() ExperienceLevel .Items.Insert(0 , "Select Experience Level") ExperienceLevel .Items(0).value = 0
ActualExperienc eLevel.DataSour ce=ExperienceLe vel.Items ActualExperienc eLevel.DataBind ()
Worked great.
Don't add your default item because it is already in the list.
Which default item - the insert?
ExperienceLevel .Items.Insert(0 , "Select Experience Level")
Thanks,
Tom Tim
"tshad" wrote:
Can you databind a dropdownlist to another dropdownlist?
I have 2 identical list. I am getting my data from a DataReader, so as soon as I have bound the first DDL, I can't do it again to the next as the dataReader can only be read once.
I tried:
ExperienceLevel .DataSource=dbR eader ExperienceLevel .DataTextField= "Descriptio n" ExperienceLevel .DataValueField ="ExperienceLev elID" ExperienceLevel .databind() ExperienceLevel .Items.Insert(0 , "Select Experience Level") ExperienceLevel .Items(0).value = 0
ActualExperienc eLevel.DataSour ce=ExperienceLe vel ActualExperienc eLevel.DataText Field= DataTextField ActualExperienc eLevel.DataValu eField=DataValu eField ActualExperienc eLevel.databind () ActualExperienc eLevel.Items.In sert(0, "Select Experience Level") ActualExperienc eLevel.Items(0) .value = 0
But that doesn't seem to work.
Thanks,
Tom
"timkling" <ti******@discu ssions.microsof t.com> wrote in message
news:A7******** *************** ***********@mic rosoft.com... Which default item - the insert?
ExperienceLevel .Items.Insert(0 , "Select Experience Level") Yes. Do it to the first list, but after that it will be in the second list automatically.
Worked as advertised.
Thanks,
Tom
Tim
"tshad" wrote:
"timkling" <ti******@discu ssions.microsof t.com> wrote in message news:D8******** *************** ***********@mic rosoft.com... > To bind to a dropdownlist the datasource must implement IListSource or > IEnumerable. DropDownList.It ems is enumerable. > > So this will work: > ExperienceLevel .DataSource=dbR eader > ExperienceLevel .DataTextField= "Descriptio n" > ExperienceLevel .DataValueField ="ExperienceLev elID" > ExperienceLevel .DataBind() > ExperienceLevel .Items.Insert(0 , "Select Experience Level") > ExperienceLevel .Items(0).value = 0 > > ActualExperienc eLevel.DataSour ce=ExperienceLe vel.Items > ActualExperienc eLevel.DataBind () >
Worked great.
> Don't add your default item because it is already in the list.
Which default item - the insert?
ExperienceLevel .Items.Insert(0 , "Select Experience Level")
Thanks,
Tom > > Tim > > "tshad" wrote: > >> Can you databind a dropdownlist to another dropdownlist? >> >> I have 2 identical list. I am getting my data from a DataReader, so as >> soon >> as I have bound the first DDL, I can't do it again to the next as the >> dataReader can only be read once. >> >> I tried: >> >> ExperienceLevel .DataSource=dbR eader >> ExperienceLevel .DataTextField= "Descriptio n" >> ExperienceLevel .DataValueField ="ExperienceLev elID" >> ExperienceLevel .databind() >> ExperienceLevel .Items.Insert(0 , "Select Experience Level") >> ExperienceLevel .Items(0).value = 0 >> >> ActualExperienc eLevel.DataSour ce=ExperienceLe vel >> ActualExperienc eLevel.DataText Field= DataTextField >> ActualExperienc eLevel.DataValu eField=DataValu eField >> ActualExperienc eLevel.databind () >> ActualExperienc eLevel.Items.In sert(0, "Select Experience Level") >> ActualExperienc eLevel.Items(0) .value = 0 >> >> But that doesn't seem to work. >> >> Thanks, >> >> Tom >> >> >>
"timkling" <ti******@discu ssions.microsof t.com> wrote in message
news:A7******** *************** ***********@mic rosoft.com... Which default item - the insert?
ExperienceLevel .Items.Insert(0 , "Select Experience Level") Yes. Do it to the first list, but after that it will be in the second list automatically. Tim
Just realized that it wasn't doing it correctly.
I have the following:
CopyResumeTo1.D ataSource = dbReader
CopyResumeTo1.D ataValueField = "UserID"
CopyResumeTo1.D ataTextField = "FullName"
CopyResumeTo1.D ataBind()
CopyResumeTo1.I tems.Insert(0, new ListItem("Selec t Current User","0"))
CopyResumeTo2.D ataSource=CopyR esumeTo1.Items
CopyResumeTo2.D ataBind()
CopyResumeTo3.D ataSource=CopyR esumeTo1.Items
CopyResumeTo3.D ataBind()
The first one (CopyResumeTo1) is working correctly. It has the
DataValueField (UserID) as an integer and the DataTextFiled (FullName) as
the name and if I look at the ViewSource, it is correct.
But when I look at the other 2 dropdowns, it is putting the FullName in both
the DataValueField and the DataTextField.
Also, I thought my insert would put a 0 in the Value field, but it put a
blank there. Is my format incorrect?
CopyResumeTo1.I tems.Insert(0, new ListItem("Selec t Current User","0")
Thanks,
Tom "tshad" wrote:
"timkling" <ti******@discu ssions.microsof t.com> wrote in message news:D8******** *************** ***********@mic rosoft.com... > To bind to a dropdownlist the datasource must implement IListSource or > IEnumerable. DropDownList.It ems is enumerable. > > So this will work: > ExperienceLevel .DataSource=dbR eader > ExperienceLevel .DataTextField= "Descriptio n" > ExperienceLevel .DataValueField ="ExperienceLev elID" > ExperienceLevel .DataBind() > ExperienceLevel .Items.Insert(0 , "Select Experience Level") > ExperienceLevel .Items(0).value = 0 > > ActualExperienc eLevel.DataSour ce=ExperienceLe vel.Items > ActualExperienc eLevel.DataBind () >
Worked great.
> Don't add your default item because it is already in the list.
Which default item - the insert?
ExperienceLevel .Items.Insert(0 , "Select Experience Level")
Thanks,
Tom > > Tim > > "tshad" wrote: > >> Can you databind a dropdownlist to another dropdownlist? >> >> I have 2 identical list. I am getting my data from a DataReader, so as >> soon >> as I have bound the first DDL, I can't do it again to the next as the >> dataReader can only be read once. >> >> I tried: >> >> ExperienceLevel .DataSource=dbR eader >> ExperienceLevel .DataTextField= "Descriptio n" >> ExperienceLevel .DataValueField ="ExperienceLev elID" >> ExperienceLevel .databind() >> ExperienceLevel .Items.Insert(0 , "Select Experience Level") >> ExperienceLevel .Items(0).value = 0 >> >> ActualExperienc eLevel.DataSour ce=ExperienceLe vel >> ActualExperienc eLevel.DataText Field= DataTextField >> ActualExperienc eLevel.DataValu eField=DataValu eField >> ActualExperienc eLevel.databind () >> ActualExperienc eLevel.Items.In sert(0, "Select Experience Level") >> ActualExperienc eLevel.Items(0) .value = 0 >> >> But that doesn't seem to work. >> >> Thanks, >> >> Tom >> >> >>
"tshad" <ts**********@f tsolutions.com> wrote in message
news:u$******** ******@TK2MSFTN GP14.phx.gbl... "timkling" <ti******@discu ssions.microsof t.com> wrote in message news:A7******** *************** ***********@mic rosoft.com... Which default item - the insert?
ExperienceLevel .Items.Insert(0 , "Select Experience Level") Yes. Do it to the first list, but after that it will be in the second list automatically. Tim
Just realized that it wasn't doing it correctly.
I have the following:
CopyResumeTo1.D ataSource = dbReader CopyResumeTo1.D ataValueField = "UserID" CopyResumeTo1.D ataTextField = "FullName" CopyResumeTo1.D ataBind() CopyResumeTo1.I tems.Insert(0, new ListItem("Selec t Current User","0"))
CopyResumeTo2.D ataSource=CopyR esumeTo1.Items CopyResumeTo2.D ataBind()
CopyResumeTo3.D ataSource=CopyR esumeTo1.Items CopyResumeTo3.D ataBind()
I found what needed to be added to make this work.
You also need the DataValueField and DataTextField defined, but refering to
the properties of the ListItem and not the original DataReader. So the
above needs to be done as so:
CopyResumeTo1.D ataSource = dbReader
CopyResumeTo1.D ataValueField = "UserID"
CopyResumeTo1.D ataTextField = "FullName"
CopyResumeTo1.D ataBind()
CopyResumeTo1.I tems.Insert(0, new ListItem("Selec t Current User","0"))
CopyResumeTo2.D ataSource=CopyR esumeTo1.Items
CopyResumeTo2.D ataValueField = "Value"
CopyResumeTo2.D ataTextField = "Text"
CopyResumeTo2.D ataBind()
CopyResumeTo3.D ataSource=CopyR esumeTo1.Items
CopyResumeTo3.D ataValueField = "Value"
CopyResumeTo3.D ataTextField = "Text"
CopyResumeTo3.D ataBind()
In DataReader you use the Column name as the source, if you use the
ListItem - there is no property "UserID" or "FullName". There are 3
properties - "Selected", "Value" and "Text". In this case, the Value and
Text properties. The first one (CopyResumeTo1) is working correctly. It has the DataValueField (UserID) as an integer and the DataTextFiled (FullName) as the name and if I look at the ViewSource, it is correct.
But when I look at the other 2 dropdowns, it is putting the FullName in both the DataValueField and the DataTextField.
Also, I thought my insert would put a 0 in the Value field, but it put a blank there. Is my format incorrect?
Actually, this format was correct, but I was doing a refresh to check it and
I was not re-loading the dropdowns, once I did, it worked fine.
Tom CopyResumeTo1.I tems.Insert(0, new ListItem("Selec t Current User","0")
Thanks,
Tom "tshad" wrote:
"timkling" <ti******@discu ssions.microsof t.com> wrote in message news:D8******** *************** ***********@mic rosoft.com... > To bind to a dropdownlist the datasource must implement IListSource or > IEnumerable. DropDownList.It ems is enumerable. > > So this will work: > ExperienceLevel .DataSource=dbR eader > ExperienceLevel .DataTextField= "Descriptio n" > ExperienceLevel .DataValueField ="ExperienceLev elID" > ExperienceLevel .DataBind() > ExperienceLevel .Items.Insert(0 , "Select Experience Level") > ExperienceLevel .Items(0).value = 0 > > ActualExperienc eLevel.DataSour ce=ExperienceLe vel.Items > ActualExperienc eLevel.DataBind () >
Worked great.
> Don't add your default item because it is already in the list.
Which default item - the insert?
ExperienceLevel .Items.Insert(0 , "Select Experience Level")
Thanks,
Tom > > Tim > > "tshad" wrote: > >> Can you databind a dropdownlist to another dropdownlist? >> >> I have 2 identical list. I am getting my data from a DataReader, so >> as >> soon >> as I have bound the first DDL, I can't do it again to the next as the >> dataReader can only be read once. >> >> I tried: >> >> ExperienceLevel .DataSource=dbR eader >> ExperienceLevel .DataTextField= "Descriptio n" >> ExperienceLevel .DataValueField ="ExperienceLev elID" >> ExperienceLevel .databind() >> ExperienceLevel .Items.Insert(0 , "Select Experience Level") >> ExperienceLevel .Items(0).value = 0 >> >> ActualExperienc eLevel.DataSour ce=ExperienceLe vel >> ActualExperienc eLevel.DataText Field= DataTextField >> ActualExperienc eLevel.DataValu eField=DataValu eField >> ActualExperienc eLevel.databind () >> ActualExperienc eLevel.Items.In sert(0, "Select Experience Level") >> ActualExperienc eLevel.Items(0) .value = 0 >> >> But that doesn't seem to work. >> >> Thanks, >> >> Tom >> >> >>
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Leon Shaw |
last post by:
have two Dropdownlist and one which is containing States and one
containing Cities. I know how to do all the little databinding task in
visual studios interface as well as set the relationship (parent, child,
etc.). In the code behind file in page_load event I fill the data adapter
and databind the State dropdownlist. I also set the on_change event for the
Cities dropdownlist after a state is selected. However, When I run this page
in the...
|
by: JV |
last post by:
It's easy to databind a listbox or dropdownlist if all you want is to fill
it with a list of values. There are plenty of examples in the online help.
Unfortunately, real world applications demand more. Usually you would also
like to bind the SelectedValue to something else. Common scenario:
You have an ADDRESS table with a foreign key to a STATE table. You join on
an integer or uniqueidentifier key value, but the STATE table is what...
|
by: Joe Gass |
last post by:
I'd like to bind some xml to a dropdownlist
<engines>
<engine name="test1" id="1" />
<engine name="test2" id="2" />
</engines>
If I do:
ddlEngines.DataSource = xmlDoc.SelectNodes("/engines/engine")
|
by: Nathan Sokalski |
last post by:
I have several DropDownList controls on my page that use databinding.
However, I want to give users the option of selecting a choice such as "None
Selected" or something else that shows they did not make a selection.
However, if I attempt to add a ListItem to the Items collection when
databinding is used it is removed and replaced by the item in the
databinding source. Is there any simple way to add an extra ListItem, or do
I have to build...
|
by: Dave A |
last post by:
I am stuggling with databinding a drop down list, hooking into the SelectedIndexChanged and attempting to avoid using the viewstate.
The drop down list is quite large so I would prefer to avoid using the view state so I set EnableViewState on the page to false. To enable the drop down list to bind to a datasource I bind it during the OnInit.
I do a response.Write during the SelectedIndexChanged event to verify that the event fires.
...
| |
by: Simon Gregory |
last post by:
I am currently attempting to figure out how the new databinding
stucture works in ASP.NET 2.0 after working with v1.0 & v1.1 for
several years.
It seems that if you wish to do set up databinding at Design Time, you
are restricted to using one of the 5 xxxDataSource controls.
The data in our websites are usually obtained via a set of webservices
and are contained in a set of strongly typed relational DataSets.
|
by: moi |
last post by:
Hello,
With ASP.NET 2 ,
i have two dropdownlist, one "A" (not in a formview) in the web page and other one "B" in a Insert Template in a formview. There's a link (parameter between this two dropdownlist.
When i selected a new item in the A dropdownlist, i have this error message :
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control"
when i disable EnableStateView for the formview,...
|
by: CorporateCoder |
last post by:
Hi,
I am trying to bind the selected value of a databound dropdown box in a
databound gridview control to the value being displayed in the template
column the dropdown box has been added to. Both the grid and the dropdown
box are retrieving and displaying data fine, I just cant bind the two
together.
I followed the instructions in the help document called 'Walkthrough:
Displaying a Drop-Down List While Editing in the GridView Web...
|
by: =?Utf-8?B?cGhpbGptY2c=?= |
last post by:
I've seen this question asked 100 times, but with no reasonable answer, other
than to extend a control etc. Sorry if I'm going over old ground.
I've a DropDownList inside a FormView control, which is hooked up to a
GridView. The contents of the DropDownList are being built from an
ObjectDataSource using business objects. Problem is, I'm binding the
DropDownList's SelectedValue to a property of type int?, and and where adding...
|
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: 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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |