473,320 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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
3 3484
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: James Bright | last post by:
I have set up custom Intellisense for our project. (In a nutshell, we will have ASP.NET controls based on many of the statndard WebControls, but with a few extensions that we will be adding). I've...
3
by: Joey | last post by:
Hi, I'm trying to add a default item to my listbox but when I do it tells me that it's not defined, could someone tell me the syntax I need to use to get the listbox control to display a default...
3
by: Chris Newby | last post by:
I have a very simple custom control that derives from WebControls.Panel and implements INamingContainer. It appear that controls created as children of my custom control are having ViewState...
0
by: Chris Newby | last post by:
I have a custom control that is essentially implemented as follows: ================================================ public class TestPanel : WebControl, INamingContainer { protected override...
4
by: Hong Yip | last post by:
Hi Everyone, I have an array of checkboxlist. Everything works prefectly fine until I start working on the "presentation" view. I am not able to "insert" a checkbox item to a table cell. ...
7
by: Girish | last post by:
OK.. phew. Playing with data grids for the past few days has been fun and a huge learning experience.. My problem. I have a requirement to display a gird with a gird. Within the embedded grid,...
3
by: Peter | last post by:
Hello, One thing I am looking to do is to create a couple of different custom Web Controls that can give me added options when specifying them in an ASP.NET page. For example: ...
0
by: webmaster | last post by:
Hi all, I'm tearing my hair out with this one. I have successfully implemented by own RadioButtonList in order to provide additional functionality and a DIV rather than TABLE-based layout in...
4
by: Kevin Blount | last post by:
As mentioned before, I'm creating a multi-lingual page where the text of the page comes from a database. This page includes a registration form which asks for address information, including the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.