linkbutton in nested repeater doesnt fire

N

Nicolas Chevet

Hi!
I've got a page with a datalist and a nested repeater in it to get
"categories" and "sub categories".
I've got link button in the datalist and in the repeater. The ones in the
datalist work fine assuming it fire itemcommand event on postback. The
problem is that the link button in the nested repeater doesnt raise any
event.

How can i catch the click event of the nested link button?
Thanks a lot.

Here's a piece of code:

<asp:datalist id="CategorieList" runat="server" HorizontalAlign="Center"
Width="90%" RepeatColumns="2"
BorderWidth="1px" GridLines="Horizontal" CellPadding="3"
BackColor="White" BorderStyle="None"
BorderColor="#E7E7FF">
<ItemTemplate>
<B>
<asp:LinkButton id=LinkFonction runat="server"
CommandName='<%#DataBinder.Eval( Container.DataItem, "strNom" )%>'
CommandArgument='<%#DataBinder.Eval( Container.DataItem,
"intIdCategorie" )%>'>
<%# DataBinder.Eval(Container.DataItem,"strNom") %>
&nbsp;(<%# DataBinder.Eval(Container.DataItem, "intIdCategorie") %>)
</asp:LinkButton></B><BR>
<asp:Repeater id=Repeater1 runat="server" DataSource='<%#
GetChildRelation(Container.DataItem,"CATEGORIES_RECURSIVE")%>'>
<itemTemplate>
&nbsp;&nbsp;&nbsp;&nbsp;
<asp:LinkButton id="Linkbutton1" CommandName='<%#DataBinder.Eval(
Container.DataItem, "strNom" )%>' CommandArgument='<%#DataBinder.Eval(
Container.DataItem, "intIdCategorie" )%>' runat="server">
<%# DataBinder.Eval(Container.DataItem,"strNom") %>
&nbsp;(<%# DataBinder.Eval(Container.DataItem, "intIdCategorie") %>)
</asp:LinkButton><br>
</itemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:datalist>
 
P

Patrik Lindholm

Hi Nicolas!

For the DataList you have an event called ItemCommand with the usual
object source parameter and DataListCommandEventArgs e

if you have a linkbutton named LinkButton1 in the datalist you can use the
following code

LinkButton linkButton = (LinkButton)e.FindControl("LinkButton1")

this way you get the linkbutton you cklicked on

Hope this helps

Regards Patrik
 
P

Patrik Lindholm

Sorry I did not read it all

Regards Patrik

Patrik Lindholm said:
Hi Nicolas!

For the DataList you have an event called ItemCommand with the usual
object source parameter and DataListCommandEventArgs e

if you have a linkbutton named LinkButton1 in the datalist you can use the
following code

LinkButton linkButton = (LinkButton)e.FindControl("LinkButton1")

this way you get the linkbutton you cklicked on

Hope this helps

Regards Patrik
 
N

Nicolas Chevet

It works fine with the datalist but not with the linkbutton in the nested
repeater.
Any solution?
 
P

Patrik Lindholm

Hi again Nicolas

Now I've found a solution that works

You have an event for the DataList called Item_Created if you do like this

private void Repeater1_ItemCommand(object source,
System.Web.UI.WebControls.RepeaterCommandEventArgs e)

{

// Lots of code

}

private void DataList1_ItemCreated(object sender,
System.Web.UI.WebControls.DataListItemEventArgs e)

{

Repeater r = (Repeater)e.Item.FindControl("Repeater1");

// Note that you have to add the eventhandler yourself

r.ItemCommand += new RepeaterCommandEventHandler(Repeater1_ItemCommand);

}

Hope this helps
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top