我们先来看html页面:
复制代码 代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<form runat="server">
<div>
<table>
<tr>
<td colspan="2">
<asp:Label runat="server" Text="更新指定数据" Font-Bold="True" ForeColor="Blue"></asp:Label></td>
</tr>
<tr>
<td colspan="2">
<asp:GridView runat="server" AutoGenerateColumns="False" CellPadding="4" Font-Size="Smaller" ForeColor="#333333" GridLines="None">
<Columns>
<asp:BoundField DataField="商品编号" HeaderText="商品编号" />
<asp:BoundField DataField="商品名称" HeaderText="商品名称" />
<asp:BoundField DataField="商品数量" HeaderText="商品数量" />
<asp:BoundField DataField="商品单价" HeaderText="商品单价" />
<asp:HyperLinkField DataNavigateUrlFields="商品编号" DataNavigateUrlFormatString="Default.aspx?商品编号={0}"
HeaderText="更新" Text="更新" />
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<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>
<tr>
<td colspan="2">
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label runat="server" Font-Size="Smaller" Text="商品名称:"></asp:Label><asp:TextBox runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label runat="server" Font-Size="Smaller" Text="商品数量:"></asp:Label>
<asp:TextBox runat="server"></asp:TextBox></td>
</tr>
<tr>
<td colspan="2">
<asp:Label runat="server" Font-Size="Smaller" Text="商品单价:"></asp:Label>
<asp:TextBox runat="server"></asp:TextBox></td>
</tr>
<tr>
<td colspan="2">
<asp:Button runat="server" Text="更新" /></td>
</tr>
</table>
</div>
</form>
由上面页面提交过来的数据我们接受然后利用sql执行更新数据库
复制代码 代码如下: