GridViewUp.aspx文件代碼:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridViewUp.aspx.cs" Inherits="gridview_GridViewUp" %>
<!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>
<table cellpadding="0" cellspacing="0" border="0" width="80%" style="font-size: 11px">
<tr>
<td align="center">
<asp:GridView ID="GridView1" runat="server" Width="100%" CellPadding="4" ForeColor="#333333"
AutoGenerateColumns="False" AllowPaging="True" PageSize="12" OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" OnRowDeleting="GridView1_RowDeleting"
DataKeyNames="id,name" OnPageIndexChanging="GridView1_PageIndexChanging" DataMember="card,price" OnRowDataBound="GridView1_RowDataBound" GridLines="None">
<Columns>
<asp:BoundField HeaderText="編號" DataField="id" ReadOnly="True" />
<asp:BoundField DataField="name" HeaderText="姓名" ReadOnly="True" />
<asp:TemplateField HeaderText="身份證號">
<ItemTemplate>
<%# Eval("card") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TBCard" Text='<%# Eval("card") %>' runat="server" Width="140px" />
</EditItemTemplate>
<ItemStyle Width="150px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="學歷">
<ItemTemplate>
<%# Eval("xueliText")%>
</ItemTemplate>
<EditItemTemplate>
<asp:HiddenField ID="HDFXueli" runat="server" Value='<%# Eval("xueli") %>' />
<asp:DropDownList ID="DDLXueli" runat="server" Width="90px" />
</EditItemTemplate>
<ItemStyle Width="100px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="價格">
<ItemTemplate>
<%# Eval("price") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TBPrice" Text='<%# Eval("price") %>' runat="server" Width="90px" />
</EditItemTemplate>
<ItemStyle Width="100px" />
</asp:TemplateField>
<asp:BoundField HeaderText="建立時間" DataField="createdate" ReadOnly="True" />
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" HeaderText="操作" />
</Columns>
<PagerSettings FirstPageText="" LastPageText="" NextPageText="" PreviousPageText="" />
<RowStyle Height="20px" BackColor="#F7F6F3" ForeColor="#333333" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
GridViewUp.aspx.cs文件代碼:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
using System.Data.SqlClient;
public partial class gridview_GridViewUp : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{