您的位置:首页 > 其它

手动绑定数据到GridView并实现编辑,删除,取消···

2008-03-24 22:20 579 查看
效果图:

<%@ 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>

</head>

<body>

<form id="form1" runat="server">

<div align="center">

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

CellPadding="4" ForeColor="#333333" GridLines="None" Height="285px"

onrowcancelingedit="GridView1_RowCancelingEdit"

onrowdeleting="GridView1_RowDeleting" onrowediting="GridView1_RowEditing"

onrowupdating="GridView1_RowUpdating" Width="771px">

<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />

<Columns>

<asp:BoundField DataField="id" HeaderText="学号" />

<asp:BoundField DataField="name" HeaderText="姓名" />

<asp:BoundField DataField="sex" HeaderText="性别" />

<asp:BoundField DataField="age" HeaderText="年龄" />

<asp:BoundField DataField="department" HeaderText="专业" />

<asp:BoundField DataField="grade" HeaderText="班级" />

<asp:CommandField HeaderText="编辑 " ShowEditButton="True" />

<asp:CommandField HeaderText="选择" ShowSelectButton="True" />

<asp:TemplateField HeaderText="删除 " ShowHeader="False">

<ItemTemplate>

<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"

CommandName="Delete" Text="删除" OnClientClick="return confirm('你确定要删除吗?')"></asp:LinkButton>

</ItemTemplate>

</asp:TemplateField>

</Columns>

<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />

<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />

<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

<EditRowStyle BackColor="#999999" />

<AlternatingRowStyle BackColor="White" ForeColor="#284775" />

</asp:GridView>

</div>

</form>

</body>

</html>

后台代码:

using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Data.SqlClient;

public partial class Default5 : System.Web.UI.Page
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: