Events with repeater items

L

Lloyd Sheen

I have a repeater that will have linkbuttons. I have googled much but
cannot find a solution to the following.

Since the items are dynamic I need to be able to attach handlers to the
linkbuttons to handle when they are clicked within server code. I can find
no examples of this.

Any examples?

Thanks
Lloyd Sheen
 
M

Masudur

I have a repeater that will have linkbuttons. I have googled much but
cannot find a solution to the following.

Since the items are dynamic I need to be able to attach handlers to the
linkbuttons to handle when they are clicked within server code. I can find
no examples of this.

Any examples?

Thanks
Lloyd Sheen

Hi...

1. Add Link Button in ItemTemplate of reapeater
2. then add a commad name in the link attribute,.,,,
3. Subscribe the ItemDataBound to customize the items more
4. Subscribe the ItemCommand and then do code for link button
clicked...

<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<!--More data bound code will go here-->
<asp:LinkButton ID="lnkSelect" Text="Select"
CommandName="Select" runat="server"></asp:LinkButton>
</ItemTemplate>
</asp:Repeater>


protected void Repeater1_ItemDataBound(object sender,
RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem ||
e.Item.ItemType == ListItemType.Item)
{
LinkButton btn = e.Item.FindControl("lnkSelect") as
LinkButton;
}
}

protected void Repeater1_ItemCommand(object source,
RepeaterCommandEventArgs e)
{
if (e.CommandName == "Select")
{
//do code
}
}



Thanks
Masudur
http://munnacs.110mb.com
 
L

Lloyd Sheen

Masudur said:
Hi...

1. Add Link Button in ItemTemplate of reapeater
2. then add a commad name in the link attribute,.,,,
3. Subscribe the ItemDataBound to customize the items more
4. Subscribe the ItemCommand and then do code for link button
clicked...

<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<!--More data bound code will go here-->
<asp:LinkButton ID="lnkSelect" Text="Select"
CommandName="Select" runat="server"></asp:LinkButton>
</ItemTemplate>
</asp:Repeater>


protected void Repeater1_ItemDataBound(object sender,
RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem ||
e.Item.ItemType == ListItemType.Item)
{
LinkButton btn = e.Item.FindControl("lnkSelect") as
LinkButton;
}
}

protected void Repeater1_ItemCommand(object source,
RepeaterCommandEventArgs e)
{
if (e.CommandName == "Select")
{
//do code
}
}



Thanks
Masudur
http://munnacs.110mb.com
Thanks, exactly what I needed.

LS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top