最近在小舖看到有關這方面的問題.....
去網路上找了一下資料...就分享給大家吧...
c#範例
GridViewConfirm.aspx
01 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridViewConfirm.aspx.cs" Inherits="GridViewConfirm" %>
02
03 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
04
05 <html xmlns="http://www.w3.org/1999/xhtml" >
06 <head runat="server">
07 <title>GridViewConfirm</title>
08 </head>
09 <body>
10 <form id="form1" runat="server">
11 <div>
12 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id"
13 DataSourceID="SqlDataSource1" EmptyDataText="沒有資料錄可顯示。" OnRowCreated="GridView1_RowCreated">
14 <Columns>
15 <asp:CommandField ButtonType="Button" HeaderText="CommandField" ShowDeleteButton="True" />
16 <asp:ButtonField ButtonType="Button" HeaderText="ButtonField" Text="刪除" CommandName="Delete" />
17 <asp:TemplateField HeaderText="TemplateField">
18 <ItemTemplate>
19 <asp:Button ID="Button1" runat="server" OnClientClick="return confirm('確定刪除嗎?')"
20 Text="刪除" CommandName="Delete" />
21 </ItemTemplate>
22 </asp:TemplateField>
23 <asp:BoundField DataField="id" HeaderText="id" ReadOnly="True" SortExpression="id" />
24 <asp:BoundField DataField="gender" HeaderText="gender" SortExpression="gender" />
25 <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
26 </Columns>
27 </asp:GridView>
28 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString %>"
29 DeleteCommand="DELETE FROM [user] WHERE [id] = @id"
30 ProviderName="<%$ ConnectionStrings:DatabaseConnectionString.ProviderName %>"
31 SelectCommand="SELECT [id], [gender], [name] FROM [user]" >
32 <DeleteParameters>
33 <asp:Parameter Name="id" Type="Int32" />
34 </DeleteParameters>
35 </asp:SqlDataSource>
36
37 </div>
38 </form>
39 </body>
40 </html>
41
GridViewConfirm.aspx.cs
執行結果:

參考網址:
http://www.blueshop.com.tw/board/show.asp?subcde=BRD20080313175621HB7&fumcde=FUM20041006161839LRJ&rplcnt=2
http://topic.csdn.net/u/20070820/16/91df12bb-3b7e-4060-bdaa-d8b4b77d02e9.html
推到 Twitter!
推到 Plurk!
回覆
發表回覆
-
標題: *
-
-
姓名: *
-
-
Email: (將不會被顯示)
-
-
Url:
-
-
回覆: *
-
-