Creating a custom button in a ListView in ASP.NET

I have a Results.aspx page that displays the result records requested using the SqlDataSource object through a ListView. I want to add a View button that appears next to each entry, and when I click, it will lead to a separate page on which information about this entry will be displayed. How to do it?

Edit

I tried what you said, citrons, and here is what I came up with:

<td>
    <asp:CheckBox ID="CheckBox1" runat="server" />
</td>
<td>
    <asp:LinkButton ID="LinkButton1" runat="server" CommandName="ViewButtonClick" CommandArgument='<%# Eval("ServiceId") %>'>View</asp:LinkButton>
</td>

And here is the method I want to call:

protected void ViewButtonClick(object sender, CommandEventArgs e)
    {
        var serviceId = Convert.ToInt32(e.CommandArgument);

        ServiceToView = DataAccessLayer.Service.Select(new Service { ServiceId = serviceId });
        Server.Transfer("~/ViewService.aspx");
    }

Unfortunately, nothing happens ... Am I missing something?

Edit - Fixed

- ! CommandName OnCommand. CommandName, CommandName OnCommand. , - CommandName?

+3
2

LinkButton ItemTemplate ListView.
  , CommandArgument LinkButton.
LinkButton. CommandEventArgs.CommandArgument

+1

, , Storm. Citronas .

FIRST: aspx LinkButton ItemTemplate CommandName CommandArgument. CommandArgument, .

<asp:LinkButton ID="lnkBtnAnswers" runat="server" CommandName="Answers"
     CommandArgument='<%# Eval("ID")%>'>Answers</asp:LinkButton>

: , , - . Citronas, "", "", "" "". "".

. MyControl.ItemCommand , , .

Protected Sub lvQuestions_Command(sender As Object, e As CommandEventArgs) Handles lvQuestions.ItemCommand
    If e.CommandName.ToLower() = "answers" Then
          hfSelectedQuestionID.Value = e.CommandArgument
    End If
End Sub

! , , , . CommandArgument .

0

Source: https://habr.com/ru/post/1794348/


All Articles