<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default5" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <link href="Style/Style.css" rel="Stylesheet" type="text/css" /> </head> <body> <form id="form1" runat="server"> <div style="text-align:center;"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:updatepanel ID="Updatepanel1" runat="server"> <ContentTemplate> <asp:Button ID="Button2" runat="server" Text="Button" onclick="Button2_Click1" /> <table id="table1" align="center" runat="server"> <tr> <td> <asp:GridView class="HeaderStyle" align="center" BorderStyle="Solid" CellPadding="3" PageSize="5" ID="GridView1" runat="server" AutoGenerateColumns="False" Width="100%"> <Columns> <asp:TemplateField HeaderText="论文题目" SortExpression="lwtitle"> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%#bind("lwtitle") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText ="论文内容" SortExpression="contxt"> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%#bind("contxt") %>' ></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="编辑" ShowHeader="False"> <ItemTemplate> <asp:Button ID="Button1" runat="server" Text="编辑" CommandName="edita" CommandArgument='<%#bind("lwid")%>'/> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="删除" ShowHeader="False"> <ItemTemplate> <asp:Button ID="Button1" runat="server" Text="删除" CommandName="del" CommandArgument='<%#bind("lwid")%>'/> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </td> </tr> </table> </ContentTemplate> </asp:updatepanel> </div> </form> </body> </html>
<%--前台代码 注意在使用updatapanel之前 引入
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>--%>
后台代码
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; public partial class Default5 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { bind(); } } public void bind() { string str = "select * from thesis"; GridView1.DataSource = SQLHelper.GetDataSet(str); GridView1.DataBind(); } protected void Button2_Click1(object sender, EventArgs e) { if (table1.Visible == false) { table1.Visible = true; } else if(table1.Visible==true) { table1.Visible = false; } } }