473,405 Members | 2,262 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,405 software developers and data experts.

Databinding to a listbox and a textbox

Hello all:

Clearly, I'm not getting it! Here is the scenario:

On a web page, I have two list boxen and a text box. The first listbox
is populated at page load time (if it is not a postback). This listbox
has AutoPostback = True. When the user selects an item from this list,
the second listbox is populated with more items relevant to this
selection. I am using an SQLDataSource web control for this. These
items are headers. I want, when an item from the second listbox is
selected, to then put some detail into a textbox.

To recap:
Parent list in listbox1
Child list in listbox2, based on listbox1 selected item (via postback)
Child detail in textbox, based on listbox2 selected item. Listbox2 has
AutoPostback = False (I don't want to reload everything when something
is selected here....)

I've tried a number of things, but I guess there is a conceptual
problem going on...

If anyone can steer me in the right direction, I will be grateful!

Regards,
zdrakec

Apr 10 '07 #1
9 3195
You can make an ajax call on selecting in the second listbox to populate
just the textbox.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"zdrakec" <zd*****@gmail.comwrote in message
news:11**********************@q75g2000hsh.googlegr oups.com...
Hello all:

Clearly, I'm not getting it! Here is the scenario:

On a web page, I have two list boxen and a text box. The first listbox
is populated at page load time (if it is not a postback). This listbox
has AutoPostback = True. When the user selects an item from this list,
the second listbox is populated with more items relevant to this
selection. I am using an SQLDataSource web control for this. These
items are headers. I want, when an item from the second listbox is
selected, to then put some detail into a textbox.

To recap:
Parent list in listbox1
Child list in listbox2, based on listbox1 selected item (via postback)
Child detail in textbox, based on listbox2 selected item. Listbox2 has
AutoPostback = False (I don't want to reload everything when something
is selected here....)

I've tried a number of things, but I guess there is a conceptual
problem going on...

If anyone can steer me in the right direction, I will be grateful!

Regards,
zdrakec

Apr 10 '07 #2
Shalom Elihayu:

Well, I was thinking about that, but alas, am unsure how to go about
it...

Regards,

zdrakec

On Apr 10, 10:45 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
You can make an ajax call on selecting in the second listbox to populate
just the textbox.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

"zdrakec" <zdra...@gmail.comwrote in message

news:11**********************@q75g2000hsh.googlegr oups.com...
Hello all:
Clearly, I'm not getting it! Here is the scenario:
On a web page, I have two list boxen and a text box. The first listbox
is populated at page load time (if it is not a postback). This listbox
has AutoPostback = True. When the user selects an item from this list,
the second listbox is populated with more items relevant to this
selection. I am using an SQLDataSource web control for this. These
items are headers. I want, when an item from the second listbox is
selected, to then put some detail into a textbox.
To recap:
Parent list in listbox1
Child list in listbox2, based on listbox1 selected item (via postback)
Child detail in textbox, based on listbox2 selected item. Listbox2 has
AutoPostback = False (I don't want to reload everything when something
is selected here....)
I've tried a number of things, but I guess there is a conceptual
problem going on...
If anyone can steer me in the right direction, I will be grateful!
Regards,
zdrakec- Hide quoted text -

- Show quoted text -

Apr 10 '07 #3
If you hesitate to use ajax, just make a normal postback. Likely you can
build in some logic to reload only the new content and keep what you want to
preserve in ViewState or server variables. How much other data do you have
on the page?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"zdrakec" <zd*****@gmail.comwrote in message
news:11*********************@d57g2000hsg.googlegro ups.com...
Shalom Elihayu:

Well, I was thinking about that, but alas, am unsure how to go about
it...

Regards,

zdrakec

On Apr 10, 10:45 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
>You can make an ajax call on selecting in the second listbox to populate
just the textbox.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

"zdrakec" <zdra...@gmail.comwrote in message

news:11**********************@q75g2000hsh.googleg roups.com...
Hello all:
Clearly, I'm not getting it! Here is the scenario:
On a web page, I have two list boxen and a text box. The first listbox
is populated at page load time (if it is not a postback). This listbox
has AutoPostback = True. When the user selects an item from this list,
the second listbox is populated with more items relevant to this
selection. I am using an SQLDataSource web control for this. These
items are headers. I want, when an item from the second listbox is
selected, to then put some detail into a textbox.
To recap:
Parent list in listbox1
Child list in listbox2, based on listbox1 selected item (via postback)
Child detail in textbox, based on listbox2 selected item. Listbox2 has
AutoPostback = False (I don't want to reload everything when something
is selected here....)
I've tried a number of things, but I guess there is a conceptual
problem going on...
If anyone can steer me in the right direction, I will be grateful!
Regards,
zdrakec- Hide quoted text -

- Show quoted text -


Apr 10 '07 #4
A good bit. What seems to be the problem is that when the first
listbox has an item selected, a postback occurs and based on the first
selection, the second listbox is cleared and items relevent to the
first selection are added (the first listbox is initialized only if
the page is not being posted back). I could make life easy on myself
with a datagrid, but I really really wanted to NOT use a grid :). My
selections are indeed showing up in the second listbox, but when I
select one, then
a) if listbox2 AutoPostback = False, nothing happens
b) if listbox2 AutoPostback = True, then at the time the
SelectedIndexChanged event handler on the second listbox is fired, the
SelectedItem property = Nothing, due to the fact that when the form
posts back, the first listbox is determining the contents of the
second. I was counting on getting that selected item to determine what
to put in the textbox.
I would be happy to attach some script to this event, rather than
using code-behind, and I would by all means prefer not to post back.
It's not that I hesitate to use ajax, it's just that I am not familiar
with it, and I am rusty besides...

Regards,
zdrakec

On Apr 10, 11:01 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
If you hesitate to use ajax, just make a normal postback. Likely you can
build in some logic to reload only the new content and keep what you want to
preserve in ViewState or server variables. How much other data do you have
on the page?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

"zdrakec" <zdra...@gmail.comwrote in message

news:11*********************@d57g2000hsg.googlegro ups.com...
Shalom Elihayu:
Well, I was thinking about that, but alas, am unsure how to go about
it...
Regards,
zdrakec
On Apr 10, 10:45 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
You can make an ajax call on selecting in the second listbox to populate
just the textbox.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
"zdrakec" <zdra...@gmail.comwrote in message
>news:11**********************@q75g2000hsh.googleg roups.com...
Hello all:
Clearly, I'm not getting it! Here is the scenario:
On a web page, I have two list boxen and a text box. The first listbox
is populated at page load time (if it is not a postback). This listbox
has AutoPostback = True. When the user selects an item from this list,
the second listbox is populated with more items relevant to this
selection. I am using an SQLDataSource web control for this. These
items are headers. I want, when an item from the second listbox is
selected, to then put some detail into a textbox.
To recap:
Parent list in listbox1
Child list in listbox2, based on listbox1 selected item (via postback)
Child detail in textbox, based on listbox2 selected item. Listbox2 has
AutoPostback = False (I don't want to reload everything when something
is selected here....)
I've tried a number of things, but I guess there is a conceptual
problem going on...
If anyone can steer me in the right direction, I will be grateful!
Regards,
zdrakec- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -

Apr 10 '07 #5
Why do you have to reload the second listbox on every postback? Why not to
make a server-side event handler for selecting an item in the first listbox
and another event handler for selecting one in the second? Then every
postback will run only the code for the event that initiated it.

It makes no difference if you put the code in a script inside the aspx page
or in a separate code-behind file.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"zdrakec" <zd*****@gmail.comwrote in message
news:11**********************@l77g2000hsb.googlegr oups.com...
>A good bit. What seems to be the problem is that when the first
listbox has an item selected, a postback occurs and based on the first
selection, the second listbox is cleared and items relevent to the
first selection are added (the first listbox is initialized only if
the page is not being posted back). I could make life easy on myself
with a datagrid, but I really really wanted to NOT use a grid :). My
selections are indeed showing up in the second listbox, but when I
select one, then
a) if listbox2 AutoPostback = False, nothing happens
b) if listbox2 AutoPostback = True, then at the time the
SelectedIndexChanged event handler on the second listbox is fired, the
SelectedItem property = Nothing, due to the fact that when the form
posts back, the first listbox is determining the contents of the
second. I was counting on getting that selected item to determine what
to put in the textbox.
I would be happy to attach some script to this event, rather than
using code-behind, and I would by all means prefer not to post back.
It's not that I hesitate to use ajax, it's just that I am not familiar
with it, and I am rusty besides...

Regards,
zdrakec

On Apr 10, 11:01 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
>If you hesitate to use ajax, just make a normal postback. Likely you can
build in some logic to reload only the new content and keep what you want
to
preserve in ViewState or server variables. How much other data do you
have
on the page?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

"zdrakec" <zdra...@gmail.comwrote in message

news:11*********************@d57g2000hsg.googlegr oups.com...
Shalom Elihayu:
Well, I was thinking about that, but alas, am unsure how to go about
it...
Regards,
zdrakec
On Apr 10, 10:45 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
You can make an ajax call on selecting in the second listbox to
populate
just the textbox.
>--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
>"zdrakec" <zdra...@gmail.comwrote in message
>>news:11**********************@q75g2000hsh.google groups.com...
Hello all:
Clearly, I'm not getting it! Here is the scenario:
On a web page, I have two list boxen and a text box. The first
listbox
is populated at page load time (if it is not a postback). This
listbox
has AutoPostback = True. When the user selects an item from this
list,
the second listbox is populated with more items relevant to this
selection. I am using an SQLDataSource web control for this. These
items are headers. I want, when an item from the second listbox is
selected, to then put some detail into a textbox.
To recap:
Parent list in listbox1
Child list in listbox2, based on listbox1 selected item (via
postback)
Child detail in textbox, based on listbox2 selected item. Listbox2
has
AutoPostback = False (I don't want to reload everything when
something
is selected here....)
I've tried a number of things, but I guess there is a conceptual
problem going on...
If anyone can steer me in the right direction, I will be grateful!
Regards,
zdrakec- Hide quoted text -
>- Show quoted text -- Hide quoted text -

- Show quoted text -


Apr 10 '07 #6
Well, here, you have put your finger on the conceptual problem I seem
to be having.
When the user makes a selection from listbox1, this determines the
contents of listbox2. It seems to me that I have to have a postback to
make this happen, since I can't seem to get the SelectedIndexChanged
event to fire for listbox1 without a postback. What you describe is
exactly the way I would (and did) do it for a Windows based app, that
is, each listbox has its own event handler for its respective
SelectedIndexChanged event. This is why I also thought of going the
ajax route...
On Apr 10, 11:24 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
Why do you have to reload the second listbox on every postback? Why not to
make a server-side event handler for selecting an item in the first listbox
and another event handler for selecting one in the second? Then every
postback will run only the code for the event that initiated it.

It makes no difference if you put the code in a script inside the aspx page
or in a separate code-behind file.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
Apr 10 '07 #7
There is no contradiction between a postback and the way of handling events
you like. Actually they work together. A postback makes the page execute
another time on the server and that is when your events fire. You don't have
to do anything postback-related in the Page_Load event. You can organize the
code in the following way:

Page_Load event:
if not poatback setup for the page
else do nothing.

SelectedIndexChanged event for listbox1:
populate listbox2.

SelectedIndexChanged event for listbox2:
populate the textbox.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"zdrakec" <zd*****@gmail.comwrote in message
news:11**********************@w1g2000hsg.googlegro ups.com...
Well, here, you have put your finger on the conceptual problem I seem
to be having.
When the user makes a selection from listbox1, this determines the
contents of listbox2. It seems to me that I have to have a postback to
make this happen, since I can't seem to get the SelectedIndexChanged
event to fire for listbox1 without a postback. What you describe is
exactly the way I would (and did) do it for a Windows based app, that
is, each listbox has its own event handler for its respective
SelectedIndexChanged event. This is why I also thought of going the
ajax route...
On Apr 10, 11:24 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
>Why do you have to reload the second listbox on every postback? Why not
to
make a server-side event handler for selecting an item in the first
listbox
and another event handler for selecting one in the second? Then every
postback will run only the code for the event that initiated it.

It makes no difference if you put the code in a script inside the aspx
page
or in a separate code-behind file.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

Apr 10 '07 #8
Hiya Eliyahu:

Well, let's see. That is the obvious, straightforward way to do it,
and for the life of me I cannot say why I didn't approach it in that
way from the beginning. I guess I was having a mental block.

As you might have guessed, of course, that now works perfectly.

Sheesh.

Shalom and toda,

zdrakec

On Apr 10, 11:54 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
There is no contradiction between a postback and the way of handling events
you like. Actually they work together. A postback makes the page execute
another time on the server and that is when your events fire. You don't have
to do anything postback-related in the Page_Load event. You can organize the
code in the following way:

Page_Load event:
if not poatback setup for the page
else do nothing.

SelectedIndexChanged event for listbox1:
populate listbox2.

SelectedIndexChanged event for listbox2:
populate the textbox.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
Apr 10 '07 #9
You are welcome.

This was not a mental block. This was one of many necessary steps one has to
make to pick up some experience. You need a lot of savlanut here.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"zdrakec" <zd*****@gmail.comwrote in message
news:11**********************@q75g2000hsh.googlegr oups.com...
Hiya Eliyahu:

Well, let's see. That is the obvious, straightforward way to do it,
and for the life of me I cannot say why I didn't approach it in that
way from the beginning. I guess I was having a mental block.

As you might have guessed, of course, that now works perfectly.

Sheesh.

Shalom and toda,

zdrakec

On Apr 10, 11:54 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
There is no contradiction between a postback and the way of handling
events
you like. Actually they work together. A postback makes the page execute
another time on the server and that is when your events fire. You don't
have
to do anything postback-related in the Page_Load event. You can organize
the
code in the following way:

Page_Load event:
if not poatback setup for the page
else do nothing.

SelectedIndexChanged event for listbox1:
populate listbox2.

SelectedIndexChanged event for listbox2:
populate the textbox.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

Apr 10 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ray Valenti | last post by:
I have a ASP listbox that I am trying to populate with two fields, one for display (Category) and one to store (ID) as the selected item. I can successfully populate and view the list. How ever...
1
by: Edward | last post by:
I am having a terrible time getting anything useful out of a listbox on my web form. I am populating it with the results from Postcode lookup software, and it is showing the results fine. What...
2
by: Colin Robinson | last post by:
Help please I have an example class called Person with 2 public properties Firstname and Lastname, I cant create a textbox on an asp.net form bound to the Person.Firstname property Can...
4
by: dtblankenship | last post by:
Hello everyone, I know this question has been asked many times in the forums, and after spending a few days reading, I am still confused as to the answer. I have a ListBox (lstBox),...
1
by: Stephen | last post by:
I have a form with a ListBox and would like to set the DataSource property at design-time but I can't seem to declare any kind of variable that will show up in the list. I have tried a traditional...
3
by: Alec MacLean | last post by:
Hi everyone, I have a ComboBox that when changed, calls a method to change the content of a ListBox. I'm also using the Listbox's SelectedIndexChanged event to change other control values on...
3
by: Ali Chambers | last post by:
Hi, I have created a listbox called "dtlist1" on my VB.NET form. I call a procedure as follows: Private Sub openfile(flname As String) dtlist1.Items.Clear() etc..
0
by: bnolingberg | last post by:
Hi all. I've been stuck on this problem for a while (I'm a newbie). I have a listbox with several collection objects, some of them being identical. When one of the collection items is selected...
3
by: Peter | last post by:
Hi! I am having some very strange behavior with my databound controls. It's taken a long time to isolate exactly what is provoking the problem, but I'm still leagues away from solving it. I...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
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...
0
agi2029
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.