Cannot assign property of a WebControl

Discussion in 'ASP .Net' started by Frédéric Mayot, Aug 8, 2004.

  1. Hi,

    I have a strange behavior with a webcontrol. It seems that under some
    conditions, it's not possible to assign a value to a property.
    theControl is a ListBox

    theControl.DataSource = someTable
    theControl.SelectedValue = "1" ' this value belongs to someTable
    theControl.DataBind()

    The property SelectedValue does not change. Can you see why ?

    Thanks.
    Fred
     
    Frédéric Mayot, Aug 8, 2004
    #1
    1. Advertisements

  2. SelectedValue selects the item with the given value. Before you do the
    DataBind, the list control has no items to select. Try doing the DataBind
    first.
     
    John Saunders, Aug 8, 2004
    #2
    1. Advertisements

  3. In ASP.NET applications, until you do not call the DataBind method in a web control the items are not created (even if you have set the DataSource propoerty). Once you call this method you can reference any item since they have already been created.

    Alan Ferrandiz
    MCDBA, MCT, MSF Practitioner
     
    Alan Ferrandiz [MCT], Aug 8, 2004
    #3
    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.