Insert label data from DataList into database

2019-09-13 10:22发布

I am using a DataBind to display images into DataList. Each of image have a button for voting.

My button to vote :

<asp:Image ID="imgFavBefore" runat="server" CssClass="voteStyle" ImageUrl="~/Img Content/love.png" Style="height: 20px; width: 20px; align-content: center;" CommandName="btnFavBefore" data-index="<%#Container.ItemIndex %>" />

And a label to display the total of the upvote when button vote clicked :

<asp:Label ID="lblVote" runat="server" Text='<%# Eval("likes")%>' CssClass="lblVoteStyle" data-index="<%#Container.ItemIndex %>" data-count="0" />

All label count is start from 0. So what I'm trying to do here is, I want to directly save the count of the upvote inside database first before the count will be displayed back in label refer to which image it belonged to.

Kindly to help me. Thank you.

EDIT :

I set my DataList like this :

<asp:DataList Width="100%" ItemStyle-horizontalalign="center" ItemStyle-Width="200px" ID="imgDataList" runat="server" RepeatColumns="3" OnItemCommand="imgDataList_ItemCommand">

Then I tried to access the button using the OnItemCommand of my DataList :

Protected Sub imgDataList_ItemCommand(source As Object, e As DataListCommandEventArgs)
        If e.CommandName = "btnFavBefore" Then
            ' some code here
        End If
    End Sub

The problem here is, my coding didn't go through imgDataList_ItemCommand

0条回答
登录 后发表回答