发生错误数据源不支持服务器端数据分页wd vb.net,sqlclient

时间:2015-03-05 06:04:49

标签: vb.net visual-studio-2010 web-services sql-server-2008 vbscript

我想在网格视图上启用分页,但我发现上面描述的错误。 listviewaspxvb代码如下。

      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Response.Write("value loop " & gvwExample.PageIndex & "</br>")

    Dim cmd As SqlCommand = New SqlCommand("SELECT  UserName,pass_word,ApplicantName,FatherName FROM userinfo", New SqlConnection(" Server=vu-it-wqs-pc\sqlexpress;Database=Test;Uid=sa;Pwd=123;"))
    Try
        Dim adp As New SqlDataAdapter(cmd)
        cmd.Connection.Open()
        Dim ds As New DataSet()
        adp.Fill(ds)

        gvwExample.DataSource = cmd.ExecuteReader()

        gvwExample.DataBind()
        adp.Dispose()
        ds.Dispose()

        cmd.Connection.Dispose()

    Catch ex As Exception
        lblStatus.Text = ex.Message



    End Try
End Sub
Protected Sub OnPaging(ByVal sender As Object, ByVal e As GridViewPageEventArgs) Handles gvwExample.PageIndexChanging
    Try
        gvwExample.PageIndex = e.NewPageIndex
        gvwExample.AllowPaging = True

        gvwExample.DataBind()
    Catch ex As Exception
        lblStatus.Text = ex.Message
    End Try
End Sub

listviewaspx代码位于

之下
     <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="listview.aspx.vb" Inherits="WebAppFramework20.listview" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
           </style>
</head>
<body>
    <form id="form1" runat="server">
   <table style="width:100%">

             <tr>
                <td>
                    <img alt="HTML5 Icon" src="images/D1.jpg" style="width:100px;height:50px" /></td>
                <td>
                    <img alt="HTML5 Icon" src="images/D2.png" style="width:600px;height:10px" /></td>
                <td>
                    <img alt="HTML5 Icon" src="images/D3.png" style="width:80px;height:80px" /></td>
            </tr>
        </table>

             <table style="width:50%">

             <tr>
                <td style="width:10px;height:10px" >
                    aaaa
                </td> <td style="width:10px;height:10px" >
                    aaaab
                </td> <td style="width:10px;height:10px" >
                    aaaac
                </td>

            </tr>
        </table>
       <br /> <br />
        <asp:GridView ID="gvwExample" runat="server"   CssClass="basix"  
             CellPadding="4" EnableModelValidation="True" ForeColor="Black"
             GridLines="Horizontal" AutoGenerateColumns="False" BackColor="White"
             BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" Width="666px"
             PageSize="5" AllowPaging="True"  OnPageIndexChanging = "OnPaging"     
           >

<Columns >




    <asp:BoundField DataField="UserName" HeaderText="First Name" />
    <asp:BoundField DataField="pass_word" HeaderText="Last Name" />
    <asp:BoundField DataField="ApplicantName" HeaderText="Date Hired" />
        <asp:BoundField DataField="FatherName" HeaderText="First Name" />
        <asp:HyperLinkField HeaderText="View Details..." Text="View Details..." DataNavigateUrlFields="UserName"
                DataNavigateUrlFormatString="DBform.aspx?ID={0}" />      
         </Columns> 

                <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
                <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
                <PagerSettings FirstPageText="First" LastPageText="Last" Mode="NumericFirstLast" />
                <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
                <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />

                </asp:GridView>
                  <asp:Label ID="lblStatus" runat="server" Text="" Width="300px" style="margin-left: 20px"></asp:Label>

        </form>
    </body>

        </html>

如果我禁用allowpaging="false"之类的分页,那么只有gridview运行良好 告诉我我做错了什么

1 个答案:

答案 0 :(得分:0)

您是否尝试使用DataSet变量ds作为数据源?

 Dim ds As New DataSet()
 adp.Fill(ds)

 gvwExample.DataSource = ds
 gvwExample.DataBind()
相关问题