Hi, i have a datagrid to display the data retrieved from database using datareader. I set custom paging to false, it will give me the following error.
Server Error in '/e-library' Application.
--------------------------------------------------------------------------------
AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID DgFaqs when AllowPaging is set to true and the selected datasource does not implement ICollection.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID DgFaqs when AllowPaging is set to true and the selected datasource does not implement ICollection.
Source Error:
Line 50: dr = cmd.ExecuteReader
Line 51: DgFaqs.DataSource = dr
Line 52: DgFaqs.DataBind()
Line 53: con.Close()
Line 54: End Sub
Source File: c:\inetpub\wwwroot\e-library\Help.aspx.
vb Line: 52
Stack Trace:
[HttpException (0x80004005): AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID DgFaqs when AllowPaging is set to true and the selected datasource does not implement ICollection.]
System.Web.UI.WebControls.DataGrid.CreateControlHi erarchy(Boolean useDataSource) +2068
System.Web.UI.WebControls.BaseDataList.OnDataBindi ng(EventArgs e) +49
System.Web.UI.WebControls.BaseDataList.DataBind() +23
e_library.Help.BindGrid() in c:\inetpub\wwwroot\e-library\Help.aspx.
vb:52
e_library.Help.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\e-library\Help.aspx.
vb:31
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032
But if I set custom paging to true, the data is displayed, but I cant navigate through the records.
Below are my coding:
Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
BindGrid()
End If
btnLogout.Attributes.Add("onclick", "return confirm('Are you sure you want to exit E-Library System?');")
End Sub
Private Sub BindGrid()
Dim a As New Common
Dim con As New SqlConnection
con = a.GetConnect()
DgFaqs.Visible = True
Dim cmd As New SqlCommand
Dim dr As SqlDataReader
cmd.CommandText = "select * from FAQs"
cmd.CommandType = CommandType.Text
cmd.Connection = con
con.Open()
dr = cmd.ExecuteReader
DgFaqs.DataSource = dr
DgFaqs.DataBind()
con.Close()
End Sub
Private Sub DgFaqs_PageIndexChanged(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs)
DgFaqs.CurrentPageIndex = e.NewPageIndex
BindGrid()
End Sub
Can somebody point out what is the problem behind this? Thanks a lot!
Irene