<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>GridView_Demo</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="myGrid" runat="server" >
</asp:GridView>
</div>
</form>
</body>
</html>
====================================
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//myself
using System.Drawing;
public partial class _Default : System.Web.UI.Page
{
private Employees.Employees_BLL bll = new Employees.Employees_BLL();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//设置GridView外观样式
setGridViewStyle();
//创建及设置Fields字段
setFields();
//设置 GridView 数据源绑定
GridBind();
}
//以后台的方式添加 GridView 的各类事件
myGrid.RowEditing += new GridViewEditEventHandler(myGrid_RowEditing);
myGrid.RowUpdating += new GridViewUpdateEventHandler(myGrid_RowUpdating);
myGrid.RowCancelingEdit += new GridViewCancelEditEventHandler(myGrid_RowCancelingEdit);
myGrid.RowDeleting += new GridViewDeleteEventHandler(myGrid_RowDeleting);
}
方法#region 方法
//设置GridView外观样式
private void setGridViewStyle()
{
myGrid.AutoGenerateColumns = false;
//设置Row的键值组成,具有唯一性