PC Review


Reply
Thread Tools Rate Thread

Adding LinkButton Controls to a BulletedList

 
 
Jonathan Wood
Guest
Posts: n/a
 
      11th Oct 2009
I want to dynamically create an unordered list where each item is a link
that posts back to the source page.

I thought it might be nice to use a BulletedList control for the list, and
create LinkButton controls for each item in the list. But the BulletedList
control doesn't allow child controls, and the ListItem object doesn't
support child controls either.

I was curious how you folks might approach this situation.

Thanks.

Jonathan


 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      12th Oct 2009
On Oct 11, 11:10*pm, "Jonathan Wood" <jw...@softcircuits.com> wrote:
> I want to dynamically create an unordered list where each item is a link
> that posts back to the source page.
>
> I thought it might be nice to use a BulletedList control for the list, and
> create LinkButton controls for each item in the list. But the BulletedList
> control doesn't allow child controls, and the ListItem object doesn't
> support child controls either.
>
> I was curious how you folks might approach this situation.
>
> Thanks.
>
> Jonathan


I think the easiest way would be to use Repeater with LinkButtons

Something like this

<UL>

<asp:Repeater ID="Repeater1" runat="server"
OnItemCommand="Repeater1_ItemCommand">
<ItemTemplate>
<LI>
<asp:LinkButton ID="LinkButton1" runat="server"
Text="Trigger" CommandName="trigger"></asp:LinkButton>
</ItemTemplate>
</asp:Repeater>

</UL>
 
Reply With Quote
 
Gregory A. Beamer
Guest
Posts: n/a
 
      12th Oct 2009
"Jonathan Wood" <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> I want to dynamically create an unordered list where each item is a
> link that posts back to the source page.
>
> I thought it might be nice to use a BulletedList control for the list,
> and create LinkButton controls for each item in the list. But the
> BulletedList control doesn't allow child controls, and the ListItem
> object doesn't support child controls either.
>
> I was curious how you folks might approach this situation.


If you want a built in .NET control, I would use the Repeater, which
allows you to start the unordered list in the header and finish in the
footer and do the "dirty work" in the middle.

If you want something you can drag and drop with no need to create tags,
a custom built control is the best option. You may be able to find an
open source one already built, or a third party control you can
purchase, that does what you want.

Peace and Grace,

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Reply With Quote
 
Jonathan Wood
Guest
Posts: n/a
 
      12th Oct 2009
"Alexey Smirnov" <(E-Mail Removed)> wrote:

> I think the easiest way would be to use Repeater with LinkButtons
>
> Something like this
>
> <UL>
>
> <asp:Repeater ID="Repeater1" runat="server"
> OnItemCommand="Repeater1_ItemCommand">
> <ItemTemplate>
> <LI>
> <asp:LinkButton ID="LinkButton1" runat="server"
> Text="Trigger" CommandName="trigger"></asp:LinkButton>
> </ItemTemplate>
> </asp:Repeater>
>
> </UL>


Thanks, I haven't worked with this control before.

I'm not exactly clear on how I can then build this list dynamically but I
should be able to figure it out. I'll check it out.

Jonathan


 
Reply With Quote
 
Jonathan Wood
Guest
Posts: n/a
 
      12th Oct 2009
"Gregory A. Beamer" <(E-Mail Removed)> wrote:

> If you want a built in .NET control, I would use the Repeater, which
> allows you to start the unordered list in the header and finish in the
> footer and do the "dirty work" in the middle.


Thanks, that's two suggestions for the same thing.

Jonathan

 
Reply With Quote
 
Gregory A. Beamer
Guest
Posts: n/a
 
      12th Oct 2009
"Jonathan Wood" <(E-Mail Removed)> wrote in news:OZwZS$0SKHA.4144
@TK2MSFTNGP02.phx.gbl:

>
> Thanks, that's two suggestions for the same thing.
>
> Jonathan


It is the easiest declarative solution. If you need to customize the
output more, then the custom control is the best option.

Peace and Grace,

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Reply With Quote
 
Jonathan Wood
Guest
Posts: n/a
 
      12th Oct 2009
"Gregory A. Beamer" <(E-Mail Removed)> wrote:

> It is the easiest declarative solution. If you need to customize the
> output more, then the custom control is the best option.


I got it working by binding to the datasource. However, it kind of annoyed
me that there is no method to add a row manually. I mean, the control does
that itself so why not expose that functionality? Perhaps I'll be okay with
the way it works now.

Thanks.

Jonathan


 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      12th Oct 2009
On Oct 12, 6:44*pm, "Jonathan Wood" <jw...@softcircuits.com> wrote:
> "Gregory A. Beamer" <NoSpamMgbwo...@comcast.netNoSpamM> wrote:
>
> > It is the easiest declarative solution. If you need to customize the
> > output more, then the custom control is the best option.

>
> I got it working by binding to the datasource. However, it kind of annoyed
> me that there is no method to add a row manually. I mean, the control does
> that itself so why not expose that functionality? Perhaps I'll be okay with
> the way it works now.
>
> Thanks.
>
> Jonathan


Well, it's true, it does not provide any built-in means for editing,
sorting, or paging of data, but it's simple. You could add new
features programmatically, but would result in a lot of code and
effort.

Actually, add a new row is not that difficult

if you bind your repeater to an array

string[] arr1 = new string[] {
"array item 1",
"array item 2",
"array item 3",
"array item 4",
"array item 5"
};

Repeater1.DataSource = arr1;
Repeater1.DataBind();

than to add a new row you would need just to add a new item to the
array and re-bind the control.

I think this should not be a big issue.

There is also another option to set <ul> </ul>. You can add the <ul>
tag to the HeaderTemplate, the </ul> tag to the FooterTemplate

<asp:Repeater...>
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li>...</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>

Hope this helps
 
Reply With Quote
 
Jonathan Wood
Guest
Posts: n/a
 
      12th Oct 2009
"Alexey Smirnov" <(E-Mail Removed)> wrote:

> Actually, add a new row is not that difficult
>
> if you bind your repeater to an array
>
> string[] arr1 = new string[] {
> "array item 1",
> "array item 2",
> "array item 3",
> "array item 4",
> "array item 5"
> };
>
> Repeater1.DataSource = arr1;
> Repeater1.DataBind();


But this adds unnecessary overhead because I must make an additional copy of
the data I'm working with. Internally, the repeater control has logic to add
a row to the output. Why not just add a method to do this manually?

Jonathan


 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      13th Oct 2009
On Oct 13, 12:51*am, "Jonathan Wood" <jw...@softcircuits.com> wrote:
> "Alexey Smirnov" <alexey.smir...@gmail.com> wrote:
> > Actually, add a new row is not that difficult

>
> > if you bind your repeater to an array

>
> > string[] arr1 = new string[] {
> > "array item 1",
> > "array item 2",
> > "array item 3",
> > "array item 4",
> > "array item 5"
> > };

>
> > Repeater1.DataSource = arr1;
> > Repeater1.DataBind();

>
> But this adds unnecessary overhead because I must make an additional copyof
> the data I'm working with. Internally, the repeater control has logic to add
> a row to the output. Why not just add a method to do this manually?
>
> Jonathan


Repeater is a data-bound container control that needs to have a data
source. I agree, array is probably not the best choice, you may
consider to use an ArrayList, where you can use Insert method as

ArrayList arr1 = new ArrayList();
arr1.Insert(0, "array item 1");
....

Repeater1.DataSource = arr1;
Repeater1.DataBind();

and then

ArrayList arr1 = (ArrayList)Repeater1.DataSource;
arr1.Insert(arr1.Count, "array item 3");

but you need to keep you data somewhere anyhow.

If you don't like to use Repeater, either try to extend the original
BulletedList (you would need to overwrite Render and RenderContents
events), or simply use LiteralControl where you can output

sb.Append("<UL>");
foreach (string s in .....your data source)
{
string x = sb.Append("<LI>")
sb.Append(....)
sb.Append("</LI>");
}
sb.Append("</UL>");

.....
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding a LinkButton to a gridview, dynamically. jack Microsoft ASP .NET 4 14th Jul 2008 08:21 PM
LinkButton Event Handling (Dynamic controls) WolfyUK Microsoft ASP .NET 2 9th Oct 2006 09:29 AM
Re: BulletedList inside BulletedList Stan SR Microsoft ASP .NET 0 31st Aug 2006 06:36 AM
Adding a linkbutton to a treenode (Asp:TreeView) mazdotnet Microsoft ASP .NET 0 1st Aug 2006 03:27 PM
Create dynamically LinkButton controls and EventHandlers Kiyomi Microsoft Dot NET 3 10th Oct 2005 02:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:43 AM.