Databinding to a listbox and a textbox

Z

zdrakec

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
 
Z

zdrakec

Shalom Elihayu:

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

Regards,

zdrakec

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




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 -
 
E

Eliyahu Goldin

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 said:
Shalom Elihayu:

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

Regards,

zdrakec

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




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 -
 
Z

zdrakec

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

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




Shalom Elihayu:
Well, I was thinking about that, but alas, am unsure how to go about
it...
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

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 -
 
E

Eliyahu Goldin

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 said:
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

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




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


On Apr 10, 10:45 am, "Eliyahu Goldin"
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
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 -
 
Z

zdrakec

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...
 
E

Eliyahu Goldin

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 said:
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...


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
 
Z

zdrakec

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
 
E

Eliyahu Goldin

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top