0

This my data list:

     <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" 
               RepeatLayout="Flow">
            <ItemTemplate>
                Titre:
                <asp:Label ID="TitreLabel" runat="server" Text='<%# Eval("Titre") %>' />
                <br />
                Description:
                <asp:Label ID="DescriptionLabel" runat="server" 
                    Text='<%# Eval("Description") %>' />
                <br />

                <asp:Image ID="Image1" runat="server" 
                 ImageUrl='<%# Eval("ID", "Handler.ashx?ID={0}") %>' Width="200" Height="200"/>

                <br />
                comments:
                <asp:Label ID="commentsLabel" runat="server" Text='<%# Eval("comments") %>' />
                <br />

                Ajouter commentaire 
                <asp:button ID="btnAjouter"  runat="server" Text="Ajouter" />
                <br/>
                <br/>
            </ItemTemplate>
        </asp:DataList>

In the Vb.aspx code I create a method:

public Sub updateComments()
.......
End Sub

And I want to add an event to my DataList button and excute the method.

I don't know how to do it correctly.

This is in Vb.net.

Thanks

Frank

1

1 Answer 1

2

You just need to add a CommandName to your button and handle the DataList's ItemCommand.

For example(in ItemTemplate)

<asp:button ID="btnAjouter" CommandName="Ajouter"  runat="server" Text="Ajouter" />

In Codebehind:

Sub Item_Command(sender As Object, e As DataListCommandEventArgs)Handles DataList1.ItemCommand
    If e.CommandName = "Ajouter"
        '  do something '
    End If
End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

Also note you can add a parameter to work with using the CommandArgument Property of the Button and access in Item_Command via e.CommandArgument. +1 :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.