Databinding to a listbox and a textbox

Discussion in 'ASP .Net' started by zdrakec, Apr 10, 2007.

  1. zdrakec

    zdrakec Guest

    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
     
    zdrakec, Apr 10, 2007
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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
    >
     
    Eliyahu Goldin, Apr 10, 2007
    #2
    1. Advertising

  3. zdrakec

    zdrakec Guest

    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"
    <> 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" <> wrote in message
    >
    > news:...
    >
    >
    >
    > > 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 -
     
    zdrakec, Apr 10, 2007
    #3
  4. 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" <> wrote in message
    news:...
    > 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"
    > <> 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" <> wrote in message
    >>
    >> news:...
    >>
    >>
    >>
    >> > 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 -

    >
    >
     
    Eliyahu Goldin, Apr 10, 2007
    #4
  5. zdrakec

    zdrakec Guest

    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"
    <> 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" <> wrote in message
    >
    > news:...
    >
    >
    >
    > > 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"
    > > <> 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" <> wrote in message

    >
    > >>news:...

    >
    > >> > 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 -
     
    zdrakec, Apr 10, 2007
    #5
  6. 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" <> wrote in message
    news:...
    >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"
    > <> 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" <> wrote in message
    >>
    >> news:...
    >>
    >>
    >>
    >> > 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"
    >> > <> 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" <> wrote in message

    >>
    >> >>news:...

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

    >
    >
     
    Eliyahu Goldin, Apr 10, 2007
    #6
  7. zdrakec

    zdrakec Guest

    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"
    <> 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
     
    zdrakec, Apr 10, 2007
    #7
  8. 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" <> wrote in message
    news:...
    > 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"
    > <> 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

    >
     
    Eliyahu Goldin, Apr 10, 2007
    #8
  9. zdrakec

    zdrakec Guest

    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"
    <> 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
    >
     
    zdrakec, Apr 10, 2007
    #9
  10. 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" <> wrote in message
    news:...
    > 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"
    > <> 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
    > >

    >
     
    Eliyahu Goldin, Apr 10, 2007
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. J. Babe

    Listbox DataBinding

    J. Babe, Jul 30, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    2,867
    J. Babe
    Jul 31, 2003
  2. Ray Valenti

    Complex databinding with ASP Listbox

    Ray Valenti, Nov 30, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    4,203
    evolve
    Dec 1, 2003
  3. Replies:
    4
    Views:
    6,749
    dblanken
    Jan 13, 2005
  4. jobs
    Replies:
    0
    Views:
    1,730
  5. Earl Teigrob
    Replies:
    1
    Views:
    437
    Shravan
    Mar 1, 2004
Loading...

Share This Page