Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Databinding to a listbox and a textbox

Reply
Thread Tools

Databinding to a listbox and a textbox

 
 
zdrakec
Guest
Posts: n/a
 
      04-10-2007
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

 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      04-10-2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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
>



 
Reply With Quote
 
 
 
 
zdrakec
Guest
Posts: n/a
 
      04-10-2007
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"
<(E-Mail Removed)> wrote:
> 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" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed) 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 -



 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      04-10-2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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"
> <(E-Mail Removed)> wrote:
>> 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" <(E-Mail Removed)> wrote in message
>>
>> news:(E-Mail Removed) 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 -

>
>



 
Reply With Quote
 
zdrakec
Guest
Posts: n/a
 
      04-10-2007
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"
<(E-Mail Removed)> wrote:
> 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" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed) 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"
> > <(E-Mail Removed)> wrote:
> >> 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" <(E-Mail Removed)> wrote in message

>
> >>news:(E-Mail Removed) 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 -



 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      04-10-2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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"
> <(E-Mail Removed)> wrote:
>> 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" <(E-Mail Removed)> wrote in message
>>
>> news:(E-Mail Removed) 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"
>> > <(E-Mail Removed)> wrote:
>> >> 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" <(E-Mail Removed)> wrote in message

>>
>> >>news:(E-Mail Removed) 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 -

>
>



 
Reply With Quote
 
zdrakec
Guest
Posts: n/a
 
      04-10-2007
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"
<(E-Mail Removed)> wrote:
> 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


 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      04-10-2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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"
> <(E-Mail Removed)> wrote:
>> 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

>



 
Reply With Quote
 
zdrakec
Guest
Posts: n/a
 
      04-10-2007
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"
<(E-Mail Removed)> wrote:
> 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
>


 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      04-10-2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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"
> <(E-Mail Removed)> wrote:
> > 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
> >

>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Databinding expressions are only supported on objects that have a DataBinding event jobs ASP .Net 0 09-25-2007 11:54 PM
Gridview encoding, or how to run commands before gridview's default databinding, or, how do I disable default databinding at all? Sergei Shelukhin ASP .Net 1 11-12-2006 01:43 PM
DataGrid Custom Column Error when DataBinding "does not contain a definition for 'DataBinding'" Earl Teigrob ASP .Net Datagrid Control 1 03-01-2004 04:52 AM
Complex databinding with ASP Listbox Ray Valenti ASP .Net 1 12-01-2003 03:54 PM
Listbox DataBinding J. Babe ASP .Net 2 07-31-2003 03:34 PM



Advertisments