datalistmain.aspx

来自「csharp课本的源代码」· ASPX 代码 · 共 67 行

ASPX
67
字号
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DataListMain.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>
        <asp:DataList ID="dataListMain" runat="server" BackColor="White" BorderColor="#E7E7FF"
            BorderStyle="None" BorderWidth="1px" CellPadding="3" DataKeyField="id" DataSourceID="sqlDataSourceMain"
            GridLines="Horizontal" OnCancelCommand="dataListMain_CancelCommand" OnEditCommand="dataListMain_EditCommand"
            OnUpdateCommand="dataListMain_UpdateCommand">
            <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
            <SelectedItemStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
            <ItemTemplate>
                学号:
                <asp:Label ID="labelId" runat="server" Text='<%# Eval("id") %>'></asp:Label><br />
                姓名:
                <asp:Label ID="labelName" runat="server" Text='<%# Eval("name") %>'></asp:Label><br />
                年龄:
                <asp:Label ID="labelAge" runat="server" Text='<%# Eval("age") %>'></asp:Label><br />
                系别:
                <asp:Label ID="labelDepartment" runat="server" Text='<%# Eval("department") %>'></asp:Label><br />
                年级:
                <asp:Label ID="labelGrade" runat="server" Text='<%# Eval("grade") %>'></asp:Label><br />
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
                <asp:LinkButton ID="linkButtonEdit" runat="server" CommandName="edit">编 辑</asp:LinkButton><br />
            </ItemTemplate>
            <EditItemTemplate>
                学号:
                <asp:Label ID="labelId" runat="server" Text='<%# Eval("id") %>'></asp:Label><br />
                姓名:<asp:TextBox ID="textBoxName" runat="server" Text='<%# Eval("name") %>'></asp:TextBox><br />
                年龄:<asp:TextBox ID="textBoxAge" runat="server" Text='<%# Eval("age") %>'></asp:TextBox><br />
                系别:<asp:TextBox ID="textBoxDepartment" runat="server" Text='<%# Eval("department") %>'></asp:TextBox><br />
                年级:<asp:TextBox ID="textBoxGrade" runat="server" Text='<%# Eval("grade") %>'></asp:TextBox><br />
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
                <asp:LinkButton ID="linkButtonSave" runat="server" CommandName="update">保 存</asp:LinkButton><br />
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
                <asp:LinkButton ID="linkButtonCancel" runat="server" CommandName="cancel">取 消</asp:LinkButton>
            </EditItemTemplate>
            <AlternatingItemStyle BackColor="#F7F7F7" />
            <ItemStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
            <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
        </asp:DataList>
        &nbsp;&nbsp;
        <asp:SqlDataSource ID="sqlDataSourceMain" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            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>
        </asp:SqlDataSource>
    
    </div>
    </form>
</body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?