日期:2014-05-17 浏览次数:20592 次
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication_GridView._Default" %> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>GridView变形</title> </head> <body> <form id="form1" runat="server"> <div> <table> <tr> <td>用户名:<asp:TextBox ID="TextBoxUserName" runat="server"></asp:TextBox> <asp:Button ID="ButtonSelect" runat="server" Text="查询" OnClick="ButtonSelect_Click"/></td> </tr> </table> <table> <tr> <td>用户列表:</td> </tr> <tr> <td> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="UserID"> <Columns> <asp:TemplateField HeaderText="全选"> <HeaderTemplate> <asp:CheckBox ID="CheckBoxSelectALL" runat="server" AutoPostBack="True" OnCheckedChanged="CheckBoxSelectALL_CheckedChanged" /> </HeaderTemplate> <ItemTemplate> <asp:CheckBox ID="CheckBoxSelect" runat="server" /> </ItemTemplate> <ItemStyle Width="100px" /> </asp:TemplateField> <asp:TemplateField HeaderText="序号"> <ItemStyle Width="100px" /> </asp:TemplateField> <asp:BoundField DataField="UserName" HeaderText="用户名" > <ItemStyle Width="100px" /> </asp:BoundField> <asp:BoundField DataField="UserAge" HeaderText="年龄"> <ItemStyle Width="100px" /> </asp:BoundField> <asp:TemplateField HeaderText="操作"> <ItemStyle Width="100px" /> </asp:TemplateField> </Columns> </asp:GridView> </td> </tr> </table> <table> <tr> <td><asp:Button ID="ButtonDeleteSelected" runat="server" Text="删除所选" /></td> </tr> </table> </div> </form> </body> </html>
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GridViewBind("select * from Users"); } } //GridView绑定 private void GridViewBind(string sqlString) {