formviewmain.aspx
来自「csharp课本的源代码」· ASPX 代码 · 共 126 行
ASPX
126 行
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FormViewMain.aspx.cs" Inherits="_Default" %>
<!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>
<br />
<asp:FormView ID="formViewMain" runat="server" AllowPaging="True" BackColor="White"
BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataSourceID="sqlDataSourceMain"
GridLines="Horizontal" OnPageIndexChanged="formViewMain_PageIndexChanged">
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<EditRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<EditItemTemplate>
学号:
<asp:TextBox ID="textBoxId" runat="server" Text='<%# Bind("id") %>' Width="75px"></asp:TextBox>
姓名:
<asp:TextBox ID="textBoxName" runat="server" Text='<%# Bind("name") %>' Width="77px"></asp:TextBox>
年龄:
<asp:TextBox ID="textBoxAge" runat="server" Text='<%# Bind("age") %>' Width="23px"></asp:TextBox><br />
系别:
<asp:TextBox ID="textBoxDepartment" runat="server" Text='<%# Bind("department") %>'
Width="122px"></asp:TextBox>
年级:
<asp:TextBox ID="textBoxGrade" runat="server" Text='<%# Bind("grade") %>' Width="91px"></asp:TextBox><br />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
Text="更 新"></asp:LinkButton>
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
Text="取 消"></asp:LinkButton>
</EditItemTemplate>
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<InsertItemTemplate>
学号:
<asp:TextBox ID="textBoxId" runat="server" Text='<%# Bind("id") %>' Width="75px"></asp:TextBox>
姓名:
<asp:TextBox ID="textBoxName" runat="server" Text='<%# Bind("name") %>' Width="77px"></asp:TextBox>
年龄:
<asp:TextBox ID="textBoxAge" runat="server" Text='<%# Bind("age") %>' Width="23px"></asp:TextBox><br />
系别:
<asp:TextBox ID="textBoxDepartment" runat="server" Text='<%# Bind("department") %>'
Width="122px"></asp:TextBox>
年级:
<asp:TextBox ID="textBoxGrade" runat="server" Text='<%# Bind("grade") %>' Width="91px"></asp:TextBox><br />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="插 入"></asp:LinkButton>
<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
Text="取 消"></asp:LinkButton>
</InsertItemTemplate>
<ItemTemplate>
学号:
<asp:Label ID="labelId" runat="server" Text='<%# Bind("id") %>'></asp:Label>
姓名:
<asp:Label ID="labelName" runat="server" Text='<%# Bind("name") %>'></asp:Label>
年龄:
<asp:Label ID="labelAge" runat="server" Text='<%# Bind("age") %>'></asp:Label> <br />
系别:
<asp:Label ID="labelDepartment" runat="server" Text='<%# Bind("department") %>'></asp:Label>
年级:
<asp:Label ID="labelGrade" runat="server" Text='<%# Bind("grade") %>'></asp:Label><br />
<br />
<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
Text="新 建"></asp:LinkButton>
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
Text="编 辑"></asp:LinkButton>
</ItemTemplate>
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
</asp:FormView>
<br />
<br />
</div>
<asp:GridView ID="gridViewMain" runat="server" AllowSorting="True" AutoGenerateColumns="False"
CellPadding="4" DataSourceID="sqlDataSourceMain" ForeColor="#333333" GridLines="None"
Width="370px">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="id" HeaderText="id" SortExpression="id" />
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
<asp:BoundField DataField="age" HeaderText="age" SortExpression="age" />
<asp:BoundField DataField="department" HeaderText="department" SortExpression="department" />
<asp:BoundField DataField="grade" HeaderText="grade" SortExpression="grade" />
</Columns>
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="sqlDataSourceMain" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
InsertCommand="Insert into information Values(@id,@name,@age,@department,@grade)"
SelectCommand="Select * from information " UpdateCommand="Update information Set name=@name,age=@age,department=@department,grade=@grade Where id=@id ">
<UpdateParameters>
<asp:Parameter Name="name" />
<asp:Parameter Name="age" />
<asp:Parameter Name="department" />
<asp:Parameter Name="grade" />
<asp:Parameter Name="id" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="id" />
<asp:Parameter Name="name" />
<asp:Parameter Name="age" />
<asp:Parameter Name="department" />
<asp:Parameter Name="grade" />
</InsertParameters>
</asp:SqlDataSource>
</form>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?