代码如下:
Imports System.Data
Imports System.Data.SqlClientPublic Class adminLog
    Inherits System.Web.UI.Page    Public conn As New SqlConnection(ConfigurationSettings.AppSettings("strConnManager"))    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '在此处放置初始化页的用户代码
        If Not IsPostBack Then
            BindGrid()
        End If    End Sub
    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        BindGrid()
    End Sub'Datagrid1的PageIndexChanged事件
    Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
        DataGrid1.CurrentPageIndex = e.NewPageIndex
        BindGrid()    End Sub '获取数据
    Function CreateDataSource() As ICollection
        Dim dt As DataTable
        Dim dr As DataRow
        Dim i As Integer        '创建数据表
        dt = New DataTable
        dt.Columns.Add(New DataColumn("操作员", GetType(String)))
        dt.Columns.Add(New DataColumn("模块名称", GetType(String)))
        dt.Columns.Add(New DataColumn("操作内容", GetType(String)))
        dt.Columns.Add(New DataColumn("操作时间", GetType(DateTime)))        Dim tmpStr As String        If DropDownList1.SelectedIndex > 0 Then
            tmpStr = tmpStr + " and ld_username= '" & DropDownList1.SelectedItem.Text & "'"
        End If        If Trim(txtModule.Text) <> "" Then
            tmpStr = tmpStr + " and ld_module ='" & txtModule.Text & "'"
        End If        Dim SqlStr As String = "select * from logdetail where (ld_time >='" & DatePicker1.Date & "' and ld_time <'" & DateAdd(DateInterval.Day, 1, DatePicker2.Date) & "')" & tmpStr & " order by ld_time"        conn.Open()
        Dim cmd As New SqlCommand(SqlStr, conn)
        Dim recordDR As SqlDataReader
        recordDR = cmd.ExecuteReader        '生成一些行,并在其中放置数据
        While recordDR.Read
            dr(0) = recordDR.Item(1).ToString
            dr(1) = recordDR.Item(2).ToString
            dr(2) = recordDR.Item(5).ToString
            dr(3) = Convert.ToDateTime(recordDR.Item(3))
            dt.Rows.Add(dr)
        End While        conn.Close()        CreateDataSource = New DataView(dt)    End Function    '绑定DataGrid1数据
    Sub BindGrid()
        DataGrid1.DataSource = CreateDataSource()
        DataGrid1.DataBind()
    End Sub调试时发现datagrid1.pagecount已经有值了,可是在页面上整个datagrid都不可见,当然基本的visible,enable属性都为true,郁闷阿!

解决方案 »

  1.   

    记录肯定是查到了,因为调试时发现datagrid1.pagecount已经有值了,可是在页面上整个datagrid都不可见,当然基本的visible,enable属性都为true,郁闷!
      

  2.   

    就是没有绑定,肯定的,粗心大意的结果啊
    在page index changed事件里面重新bindgrid
      

  3.   

    怎么都沒有看到妳的bindgrid()函數呢??只看到了得createdatasource()函數,我想妳的bindgrid()函數應該換成createdatasource()函數吧?!妳的createdatasource()函數才是數据源
      

  4.   

    不好意思,你们都错了,其实程序已经非常的完整,后来我一不小心就发现了问题所在,原来datagrid的一个属性应设成True,而开始的时候没设,真是郁闷,搞定了!
      

  5.   

    将取数据的函数放在if(!IsPostBack)的外面,
    DataGrid.DataSource=dt;
    DataGrid.DataBind();
    放在if(!IsPostBack)的里面.