DataGrid Paging / ICollection Error [JSCRIPT]

H

HP

hi,
I have a problem with my datagrid paging code, I dont know what's wrong with
that, here is what i got as the error:

AllowCustomPaging must be true and VirtualItemCount must be set for a
DataGrid with ID myDataGrid when AllowPaging is set to true and the selected
datasource does not implement ICollection.

Here is my code:

<script runat="server" language="Jscript">

function Page_Load(sender:Object, e:EventArgs) {
if (!Page.IsPostBack) {
BindData()
}
}

function BindData() {
var ds = new DataSet;
var strSQL = new String;

strSQL = "SELECT * FROM pubs ORDER BY name"
var DBConnection = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:/web/data.mdb")
var DBCommand = new OleDbCommand(strSQL, DBConnection)

DBConnection.Open();
var DBReader = DBCommand.ExecuteReader();
myDataGrid.DataSource = DBReader
myDataGrid.DataBind()
}

function myDataGrid_PageChanger(sender:Object,
e:DataGridPageChangedEventArgs) {
myDataGrid.CurrentPageIndex = e.NewPageIndex;
BindData()
}
</script>


Thanks a lot
 
G

Guest

Hi HP,

Change you code as follows

function BindData() {
var ds = new DataSet;
var strSQL = new String;

strSQL = "SELECT * FROM pubs ORDER BY name"
var DBConnection = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:/web/data.mdb")
var DBCommand = new OleDbCommand(strSQL, DBConnection)

DBConnection.Open();
var DBReader = DBCommand.ExecuteReader();
try{
myDataGrid.DataSource = DBReader
myDataGrid.DataBind()
}

Catch
{
myDataGrid.CurrentPageIndex=0
myDataGrid.DataSource = DBReader
myDataGrid.DataBind()
}

Now your code should work

Cheers,

Jerome. M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top