简体   繁体   English

数据列表中的asp.net按钮可转到另一个网页

[英]asp.net button inside a datalist to go to another webpage

I need the button inside the datalist to open another page. 我需要数据列表中的按钮来打开另一个页面。 However the response.redirect does not work ! 但是response.redirect不起作用!

here is the html 这是HTML

<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="Server">

<div id="content">
    <!-- Review -->
    <div class="products">
        <h3>My Books</h3>
        <h4>Items you have purchased</h4>
        <br />
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"></asp:SqlDataSource>

        <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" Width="618px" Height="114px">
            <ItemTemplate>

                <asp:Label ID="bookid" runat="server" Text='<%# Eval ("BookID") %>' Visible=" false"></asp:Label>
                <asp:Label ID="bookname" runat="server" Text='<%# Eval ("Title") %>'></asp:Label>
                <asp:Button ID="review" runat="server" Text="Review" CommandName="review" />

            </ItemTemplate>
        </asp:DataList>
        <br />
    </div>
</div>

below is the cs file 下面是cs文件

public void DataList1_ItemCommand(Object source, DataListCommandEventArgs e)
{
    if (e.CommandName == "review")
    {
        DataList1.SelectedIndex = e.Item.ItemIndex;
        Label bookid = (Label)DataList1.SelectedItem.FindControl("Bookid");
        Response.Redirect("Review.aspx");
    }


}

You still need to attach ItemCommand event to DataList1 . 您仍然需要将ItemCommand事件附加到DataList1

<asp:DataList OnItemCommand="DataList1_ItemCommand" ...>
      ...
</asp:DataList>

尝试Server.Transfer("Review.aspx", true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM