By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,680 Members | 1,890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,680 IT Pros & Developers. It's quick & easy.

Databinding to a listbox and a textbox

P: n/a
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
Share this Question
Share on Google+
9 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.