default
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default
<!DOCTYPE html PUBLIC "
<html xmlns="
<head runat="server">
<title></title>
</head>
<body>
<form id="form
<div>
<!
<asp:GridView ID="GridView
onpageindexchanging="GridView
onrowediting="GridView
onrowdeleting="GridView
onselectedindexchanging="GridView
<Columns>
<asp:TemplateField HeaderText="編號" Visible="False">
<ItemTemplate>
<asp:Label ID="lblNum" runat="server" Text=
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="姓名">
<EditItemTemplate>
<asp:TextBox ID="txtTableName" runat="server" Text=
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="地址">
<EditItemTemplate>
<asp:TextBox ID="txtTextName" runat="server" Text=
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="狀態" ShowSelectButton="True" />
<asp:CommandField HeaderText="編輯" ShowEditButton="True" />
<asp:CommandField HeaderText="刪除" ShowDeleteButton="True" />
</Columns>
</asp:GridView>
<br />
<asp:Button ID="btnAdd" runat="server" onclick="btnAdd_Click" Text="添加" />
<br />
<br />
</div>
</form>
</body>
</html>
default
using System;
using System
using System
using GPS_Web
using System
namespace GPS_Web
{
/// <summary>
/// </summary>
public partial class Default : System
{
protected void Page_Load(object sender
{
if (!Page
{
GridViewBind();
}
}
private void GridViewBind()
{
string sql = "select Num
try
{ //綁定數據源
GridView
GridView
}
catch (Exception ex){}
}
protected void GridView
{
GridView
GridViewBind();
}
protected void GridView
{
GridView
GridViewBind();
}
protected void GridView
{ //gridview編輯項索引等於單擊行的索引
GridView
GridViewBind();
}
/// <summary>
/// 修改事件
/// </summary>
protected void GridView
{ //取出編號
int Num = Convert
//獲取修改的值的內容
string TableName = ((TextBox)GridView
string TextName = ((TextBox)GridView
//更新記錄
string sql = string
try
{
int i = SqlHelper
if (i >
{
ClientScript
}
else
{
ClientScript
}
}
catch (Exception ex)
{
ClientScript
}
GridView
GridViewBind();
}
/// <summary>
/// 刪除事件
/// </summary>
protected void GridView
{
//取出編號
int Num = Convert
//更新記錄
string sql = string
try
{
int i = SqlHelper
if (i >
{
ClientScript
}
else
{
ClientScript
}
}
catch (Exception ex)
{
ClientScript
}
GridView
GridViewBind();
}
/// <summary>
/// 添加按鈕
/// </summary>
protected void btnAdd_Click(object sender
{
Response
}
protected void GridView
{
//行號
int i = e
GridViewRow row = GridView
btnAdd
}
}
}
執行後的頁面效果
From:http://tw.wingwit.com/Article/program/net/201311/14171.html