.net2.0中的GRIDVIEW控件使用

在.net1.1里学习了datagrid,在.net2.0里又出现了gridview,今天初次学习了GRIDVIEW的基本操作,发现它比DATAGRID使用起来更加方便,功能更好。有了GRIDVIEW,连接数据库并在页面上操作数据显得非常简单,效率更高,一整套的数据显示、删除、更新等操作在短短的代码就可以完成。下面是我学习GRIDVIEW控件时的源代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="gridview.aspx.cs" Inherits="gridview" %>
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
            AutoGenerateColumns="False" DataSourceID="AccessDataSource1" DataKeyNames="stu_xh">
            <Columns>
                <asp:BoundField  DataField="stu_xh" HeaderText="stu_xh" SortExpression="stu_xh" />
                <asp:BoundField  DataField="stu_pwd" HeaderText="stu_pwd" SortExpression="stu_pwd" />
                <asp:BoundField DataField="stu_clsBDM" HeaderText="stu_clsBDM" SortExpression="stu_clsBDM" />
                <asp:BoundField DataField="stu_sfzh" HeaderText="stu_sfzh" SortExpression="stu_sfzh" />
                <asp:CommandField ShowDeleteButton="True" />
                <asp:BoundField DataField="stu_name" HeaderText="stu_name" SortExpression="stu_name" />
                <asp:CommandField ShowEditButton="True" />
            </Columns>
        </asp:GridView>
        <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/ratvu_pj.mdb"
            SelectCommand="SELECT [stu_xh], [stu_pwd], [stu_clsBDM], [stu_sfzh], [stu_name] FROM [student]" OnSelecting="AccessDataSource1_Selecting" DeleteCommand="delete from student where stu_xh=@stu_xh" UpdateCommand="update student set stu_name=@stu_name,stu_pwd=@stu_pwd where stu_xh=@stu_xh"
             OldValuesParameterFormatString="a">
             <UpdateParameters>
                <asp:Parameter Name="stu_name" Type="String" />
                <asp:Parameter Name="stu_pwd" Type="String" />                
            </UpdateParameters>

             </asp:AccessDataSource>
   
    </div>
    </form>
</body>
</html>

 

           红色部分是我以后要注意的,因为没有DataKeyNames我不能实现所有数据的操作,没有设置<pdateParameters>我就不能实现数据的正常更新,当时没注意这两点让我费了一些时间下次要注意了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值