我在 TemplateField 中有一个带有按钮的 GridView。当我单击由 TemplateField 生成的按钮之一时,会出现母版页内容,但没有出现我实际加载的页面中的任何内容。我什至有一个 OutputLabel(用于调试目的),它位于与 GridView 或包含 GridView 的 div 相关的任何内容之外,它也没有。
内容页:
<%@ Page Title="Administration" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Admin.aspx.cs" Inherits="Default2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="mainCon" Runat="Server">
<div id="container" class="left-margin">
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="CustomGetAllUsers" TypeName="Helper"></asp:ObjectDataSource>
<asp:GridView runat="server" ID="UserGrid" CssClass="UserList" AllowPaging="True" AllowSorting="True" AllowCustomPaging="True" DataSourceID="ObjectDataSource1" CellPadding="4" ForeColor="#333333" GridLines="None" style="margin: auto">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" Height="50"/>
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
<Columns>
<asp:TemplateField runat="server">
<ItemTemplate>
<asp:Button ID="EditButton" runat="server" Text="Rediger" BorderColor="LightBlue" BackColor="LightGray" BorderWidth="3px" BorderStyle="Solid" OnClick="EditButton_Click"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<asp:Label runat="server" ID="OutputLabel" />
</asp:Content>
点击时执行的代码:
protected void EditButton_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
GridViewRow gvr = (GridViewRow)btn.NamingContainer;
HttpCookie cookie = new HttpCookie("Username", gvr.Cells[2].Text);
Response.Cookies.Add(cookie);
Response.Redirect("~/UserAdmin.aspx");
}