By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,230 Members | 2,436 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,230 IT Pros & Developers. It's quick & easy.

how do I add an custom attribute to a listitem inside a dynamically created listbox?

P: n/a
Hi everyone, I have a asp.net listbox (lstAvailable) that is populated via
as ADO DataSet.

[vbcode]

lstAvailable.DataSource = oDs

lstAvailable.DataTextField = oDs.Tables(0).Columns(0).ToString

lstAvailable.DataBind()

[/vbcode]

This works fine, but what I would like to do is for each item in the listbox
associated a new attribute to it. Given that each item in the list box has a
Text attribute and a Value attribute, I would like to add another attribute
called PersonID.

I tried this

lstAvailable.Attributes.Add("ContributorType",
oDs.Tables(0).Columns("PersonID").ToString)

But this adds the attribute to the listbox not to each individual item in
the list..

Thanks for any help in advance

Mark
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Adding attributes to the listitems doesn't actually do anything, even though
you can write the code that seems to do it. I would suggest just retrieving
the value from the table as needed.

"John" <JD@noSpam.com> wrote in message news:c7**********@lust.ihug.co.nz...
Hi everyone, I have a asp.net listbox (lstAvailable) that is populated via
as ADO DataSet.

[vbcode]

lstAvailable.DataSource = oDs

lstAvailable.DataTextField = oDs.Tables(0).Columns(0).ToString

lstAvailable.DataBind()

[/vbcode]

This works fine, but what I would like to do is for each item in the listbox associated a new attribute to it. Given that each item in the list box has a Text attribute and a Value attribute, I would like to add another attribute called PersonID.

I tried this

lstAvailable.Attributes.Add("ContributorType",
oDs.Tables(0).Columns("PersonID").ToString)

But this adds the attribute to the listbox not to each individual item in
the list..

Thanks for any help in advance

Mark

Nov 18 '05 #2

P: n/a
Hi Rick, thanks for your help, yep, gettring the info from the database was
my second option but I was just trying to save a dbase call
Cheers
Mark

"Rick Spiewak" <ri*********@mindspring.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Adding attributes to the listitems doesn't actually do anything, even though you can write the code that seems to do it. I would suggest just retrieving the value from the table as needed.

"John" <JD@noSpam.com> wrote in message news:c7**********@lust.ihug.co.nz...
Hi everyone, I have a asp.net listbox (lstAvailable) that is populated via as ADO DataSet.

[vbcode]

lstAvailable.DataSource = oDs

lstAvailable.DataTextField = oDs.Tables(0).Columns(0).ToString

lstAvailable.DataBind()

[/vbcode]

This works fine, but what I would like to do is for each item in the

listbox
associated a new attribute to it. Given that each item in the list box has a
Text attribute and a Value attribute, I would like to add another

attribute
called PersonID.

I tried this

lstAvailable.Attributes.Add("ContributorType",
oDs.Tables(0).Columns("PersonID").ToString)

But this adds the attribute to the listbox not to each individual item

in the list..

Thanks for any help in advance

Mark


Nov 18 '05 #3

P: n/a
Instead of using -- asp:listbox, use HTML SELECT.

<SELECT size="10" id="nGroup" name="nGroup" runat="server">
</SELECT>
Declare the control in code behind page --
Protected WithEvents nGroup As System.Web.UI.HtmlControls.HtmlSelect

Then add attributes to the listitems as
ls.Attributes.Add("key", .....)
Hope that helps
Kiran

Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.