Ok I'm pulling data in from an SQL database. The data is separated with commas and I would like to display each item as a bullet in a BulletedList. Is this doable? If so how? Here's what I have, I know it's not much but I can't find much info on doing this
so I'm stuck.
Ok I'm pretty new to ASP so I'm not sure I follow. The data already has the commas in it so I need to do something else with it? When you say split data by comma what exactly do you mean and how do I go about doing that?
I can connect to the SQLDataSource without any troubles. The problem is I want to make my list add a bullet at every comma. This is how my data currently displays:
Item 1, Item 2, Item 3
I would like it to separate each item using the commas though so it displays like this:
But the items are stored as one string separated by commas. The items are stored as "Item 1, Item 2, Item 3." When I use the previous code it just displays it all as one bullet.
ikeAndy
Member
40 Points
29 Posts
Comma Separated BulletedList
Feb 21, 2012 06:21 PM|LINK
Ok I'm pulling data in from an SQL database. The data is separated with commas and I would like to display each item as a bullet in a BulletedList. Is this doable? If so how? Here's what I have, I know it's not much but I can't find much info on doing this so I'm stuck.
<asp:BulletedList ID="BulletedList1" runat="server"
DataSourceID="SqlDataSource2" DataTextField="Options">
</asp:BulletedList>
Shellymn
Contributor
2600 Points
484 Posts
Re: Comma Separated BulletedList
Feb 21, 2012 06:31 PM|LINK
Yes ,
After getting data from DB , you need to create a datasouce for BulletedList . this source should have a collection , need to split data by comma .
ikeAndy
Member
40 Points
29 Posts
Re: Comma Separated BulletedList
Feb 21, 2012 06:36 PM|LINK
Ok I'm pretty new to ASP so I'm not sure I follow. The data already has the commas in it so I need to do something else with it? When you say split data by comma what exactly do you mean and how do I go about doing that?
rajsedhain
Contributor
4181 Points
1041 Posts
Re: Comma Separated BulletedList
Feb 21, 2012 07:46 PM|LINK
You have to assign DataValueField as well. Try this:
more:
http://www.ezineasp.net/post/Using-ASP-Net-BulletedList-Control-with-SQL-DataSource.aspx
Raj Sedhain
ikeAndy
Member
40 Points
29 Posts
Re: Comma Separated BulletedList
Feb 21, 2012 08:09 PM|LINK
I can connect to the SQLDataSource without any troubles. The problem is I want to make my list add a bullet at every comma. This is how my data currently displays:
I would like it to separate each item using the commas though so it displays like this:
Does that make more sense?
rajsedhain
Contributor
4181 Points
1041 Posts
Re: Comma Separated BulletedList
Feb 21, 2012 08:12 PM|LINK
Yes, just use my previous code.
do not use the comma separated list. Just use the sqldatasouce as datasourceId.
use sqldatasource to get data from database and bind that to bulletlist control.
Raj Sedhain
ikeAndy
Member
40 Points
29 Posts
Re: Comma Separated BulletedList
Feb 21, 2012 08:21 PM|LINK
But the items are stored as one string separated by commas. The items are stored as "Item 1, Item 2, Item 3." When I use the previous code it just displays it all as one bullet.
rajsedhain
Contributor
4181 Points
1041 Posts
Re: Comma Separated BulletedList
Feb 21, 2012 08:22 PM|LINK
ok, got it. So you have stored that way on database, right ?
Raj Sedhain
ikeAndy
Member
40 Points
29 Posts
Re: Comma Separated BulletedList
Feb 21, 2012 08:23 PM|LINK
Yeah that's correct
rajsedhain
Contributor
4181 Points
1041 Posts
Re: Comma Separated BulletedList
Feb 21, 2012 08:29 PM|LINK
split that list into an array and then simple lloop to grab and assign a bullet in code behind.
Raj Sedhain