ListBox and SelectedItem.Value

Discussion in 'ASP .Net' started by Mike, Jul 13, 2004.

  1. Mike

    Mike Guest

    Hello,

    I have a web form with a Listbox. When trying to read the value of the last selected item with the statement below, I always get the first item, even if the user selected another item:
    lstGrants.SelectedItem.Value)


    I am new to ASP.NET, so I don't know whether AutoPostback should be set to true. This is a subject that it is still not clear to me. Also, when setting Autopostback to true, there is some data transfer between client and server (if I am not wrong) that I would like to avoid.

    Any suggestion would be very welcome. I am having a hard time learning ASP.NET!

    Thank you very much.
    Mike
     
    Mike, Jul 13, 2004
    #1
    1. Advertisements

  2. Mike

    Raterus Guest

    sounds like you are rebinding the data to the listbox on every page_load, use..

    if not page.ispostback then
    'bind data
    end if

    Hello,

    I have a web form with a Listbox. When trying to read the value of the last selected item with the statement below, I always get the first item, even if the user selected another item:
    lstGrants.SelectedItem.Value)


    I am new to ASP.NET, so I don't know whether AutoPostback should be set to true. This is a subject that it is still not clear to me. Also, when setting Autopostback to true, there is some data transfer between client and server (if I am not wrong) that I would like to avoid.

    Any suggestion would be very welcome. I am having a hard time learning ASP.NET!

    Thank you very much.
    Mike
     
    Raterus, Jul 13, 2004
    #2
    1. Advertisements

  3. Alternative you can use 1stGrant.SelectedValue also.

    Where do you bind the ListBox ? In the load_Page method ? If yes, Do you
    bind the ListBox everytime the page is loaded or only for the fist call ?
    The right answer is only for the first call.

    if(!IsPostBack)
    {
    ......bind the list box
    }
    In the properties page of the control you can find this property.
    Yes sure. The post back mechanism send to the server the page content. For
    more informations see this link:
    http://msdn.microsoft.com/library/d...on/html/vbconwebformspageprocessingstages.asp
    For a fast begin use the quickstart tutorial ;-)
    http://www.asp.net/Tutorials/quickstart.aspx
     
    Davide Vernole [MVP], Jul 13, 2004
    #3
  4. Mike

    Mike Guest

    Thanks.


    Alternative you can use 1stGrant.SelectedValue also.

    Where do you bind the ListBox ? In the load_Page method ? If yes, Do you
    bind the ListBox everytime the page is loaded or only for the fist call ?
    The right answer is only for the first call.

    if(!IsPostBack)
    {
    .....bind the list box
    }
    In the properties page of the control you can find this property.
    Yes sure. The post back mechanism send to the server the page content. For
    more informations see this link:
    http://msdn.microsoft.com/library/d...on/html/vbconwebformspageprocessingstages.asp
    For a fast begin use the quickstart tutorial ;-)
    http://www.asp.net/Tutorials/quickstart.aspx
     
    Mike, Jul 13, 2004
    #4
  5. Mike

    Mike Guest

    Thanks.


    sounds like you are rebinding the data to the listbox on every page_load, use..

    if not page.ispostback then
    'bind data
    end if

    Hello,

    I have a web form with a Listbox. When trying to read the value of the last selected item with the statement below, I always get the first item, even if the user selected another item:
    lstGrants.SelectedItem.Value)


    I am new to ASP.NET, so I don't know whether AutoPostback should be set to true. This is a subject that it is still not clear to me. Also, when setting Autopostback to true, there is some data transfer between client and server (if I am not wrong) that I would like to avoid.

    Any suggestion would be very welcome. I am having a hard time learning ASP.NET!

    Thank you very much.
    Mike
     
    Mike, Jul 13, 2004
    #5
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.