ListBox problem

Discussion in 'ASP .Net Web Controls' started by cindy liu, Aug 3, 2005.

  1. cindy liu

    cindy liu Guest

    Hi,

    On my ASP.net page, I have a web control list box. In Page_Load method, I
    created a ListItem and added it to the list box. Here is the code:

    oItem=new ListItem(strAsset);
    oItem.Attributes.Add("Area","my area");
    lstAsset.Items.Add(oItem);

    After clicking Add button on my page, I tried to get selected list item and
    retrieve my attribute "Area". I noticed that the list item attribute count is
    0. Where is my attribute? Any idea?

    Thanks in advance!!!
    Cindy
     
    cindy liu, Aug 3, 2005
    #1
    1. Advertising

  2. cindy liu

    cindy liu Guest

    But I still can get oItem.Text and oItem.Value if I set value when creating
    my list item. That means my item is still there, just the custom attributes
    are stripped out. Why?

    Thanks in advance!!!
    Cindy

    "intrader" wrote:

    > On Tue, 02 Aug 2005 17:15:02 -0700, cindy liu wrote:
    >
    > > Hi,
    > >
    > > On my ASP.net page, I have a web control list box. In Page_Load method, I
    > > created a ListItem and added it to the list box. Here is the code:
    > >
    > > oItem=new ListItem(strAsset);
    > > oItem.Attributes.Add("Area","my area");
    > > lstAsset.Items.Add(oItem);
    > >
    > > After clicking Add button on my page, I tried to get selected list item and
    > > retrieve my attribute "Area". I noticed that the list item attribute count is
    > > 0. Where is my attribute? Any idea?
    > >
    > > Thanks in advance!!!
    > > Cindy

    > Perhaps you need to add the listbox to the controls in the page:
    > Controls.Add(oItem);
    >
    >
     
    cindy liu, Aug 5, 2005
    #2
    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. blenderdude
    Replies:
    0
    Views:
    1,104
    blenderdude
    Aug 3, 2003
  2. DC Gringo
    Replies:
    0
    Views:
    413
    DC Gringo
    Apr 6, 2004
  3. kent
    Replies:
    1
    Views:
    891
    Andrew de la Harpe
    May 3, 2004
  4. Simon Prince
    Replies:
    2
    Views:
    3,355
    =?Utf-8?B?TWljaGFlbCBUYXlsb3I=?=
    Oct 19, 2004
  5. Chris Kettenbach

    Listbox selection to populate another listbox?

    Chris Kettenbach, Jun 15, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    1,661
    Chris Kettenbach
    Jun 16, 2005
Loading...

Share This Page