使用FormView控件

<div>

        <asp:FormView ID="FormView1" runat="server" AllowPaging="True" DataSourceID="SqlDataSource1" DataKeyNames="StuID">

            <EditItemTemplate>

                StuID:

                <asp:TextBox ID="StuIDTextBox" runat="server" Text='<%# Bind("StuID") %>'>

                </asp:TextBox><br />

                Stuname:

                <asp:TextBox ID="StunameTextBox" runat="server" Text='<%# Bind("Stuname") %>'>

                </asp:TextBox><br />

                Stuage:

                <asp:TextBox ID="StuageTextBox" runat="server" Text='<%# Bind("Stuage") %>'>

                </asp:TextBox><br />

                Address:

                <asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>'>

                </asp:TextBox><br />

                Zip:

                <asp:TextBox ID="ZipTextBox" runat="server" Text='<%# Bind("Zip") %>'>

                </asp:TextBox><br />

                Grade:

                <asp:TextBox ID="GradeTextBox" runat="server" Text='<%# Bind("Grade") %>'>

                </asp:TextBox><br />

                Class:

                <asp:TextBox ID="ClassTextBox" runat="server" Text='<%# Bind("Class") %>'>

                </asp:TextBox><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>

            <InsertItemTemplate>

                StuID:

                <asp:TextBox ID="StuIDTextBox" runat="server" Text='<%# Bind("StuID") %>'>

                </asp:TextBox><br />

                Stuname:

                <asp:TextBox ID="StunameTextBox" runat="server" Text='<%# Bind("Stuname") %>'>

                </asp:TextBox><br />

                Stuage:

                <asp:TextBox ID="StuageTextBox" runat="server" Text='<%# Bind("Stuage") %>'>

                </asp:TextBox><br />

                Address:

                <asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>'>

                </asp:TextBox><br />

                Zip:

                <asp:TextBox ID="ZipTextBox" runat="server" Text='<%# Bind("Zip") %>'>

                </asp:TextBox><br />

                Grade:

                <asp:TextBox ID="GradeTextBox" runat="server" Text='<%# Bind("Grade") %>'>

                </asp:TextBox><br />

                Class:

                <asp:TextBox ID="ClassTextBox" runat="server" Text='<%# Bind("Class") %>'>

                </asp:TextBox><br />

                <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="New"

                    Text="插入">

                </asp:LinkButton>

                <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"

                    Text="取消">

                </asp:LinkButton>

            </InsertItemTemplate>

            <ItemTemplate>

                StuID:

                <asp:Label ID="StuIDLabel" runat="server" Text='<%# Bind("StuID") %>'></asp:Label><br />

                Stuname:

                <asp:Label ID="StunameLabel" runat="server" Text='<%# Bind("Stuname") %>'></asp:Label><br />

                Stuage:

                <asp:Label ID="StuageLabel" runat="server" Text='<%# Bind("Stuage") %>'></asp:Label><br />

                Address:

                <asp:Label ID="AddressLabel" runat="server" Text='<%# Bind("Address") %>'></asp:Label><br />

                Zip:

                <asp:Label ID="ZipLabel" runat="server" Text='<%# Bind("Zip") %>'></asp:Label><br />

                Grade:

                <asp:Label ID="GradeLabel" runat="server" Text='<%# Bind("Grade") %>'></asp:Label><br />

                Class:

                <asp:Label ID="ClassLabel" runat="server" Text='<%# Bind("Class") %>'></asp:Label><br />

                <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Edit">编辑</asp:LinkButton>&nbsp;

                <asp:LinkButton ID="LinkButton2" runat="server" CommandName="Delete">删除</asp:LinkButton>&nbsp;

                <asp:LinkButton ID="LinkButton3" runat="server" CommandName="New">插入</asp:LinkButton>

            </ItemTemplate>

        </asp:FormView>

        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DatabindControlsConnectionString %>"

            SelectCommand="SELECT * FROM [student]"

            InsertCommand="INSERT INTO student(stuID,Stuname,Stuage,Address,Zip,Grade,Class) VALUES (@stuID,@Stuname,@Stuage,@Address,@Zip,@Grade,@Class)"                 

            UpdateCommand="UPDATE student SET stuID=@StuID,Stuname=@Stuname,Stuage=@Stuage,Address=@Address,Zip=@Zip,Grade=@Grade,Class=@Class WHERE StuID=@StuID"

            DeleteCommand="DELETE from student WHERE StuID=@StuID">

            <DeleteParameters>

                <asp:Parameter Name="StuID" DefaultValue="0" />

            </DeleteParameters>

 

        </asp:SqlDataSource>   

    </div>

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值