sammyDashoe
Programmer
Hi there, i'm tryin to pass to the DataAdapter.Fill method a startRecordIndex, max records, but on cliking Next button which calls nextClick, the pageIndex increment does not increase after 1 and no errors are thrown. When i click the Next button nothing happens, please help.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class Home : System.Web.UI.Page
{
//Connection
OleDbConnection dbConn;
//discount that can be change by user using a gui interface
//CurrentPage
int pageIndex = 0;
double discount = 0.15 ;
protected void Page_Load(object sender, EventArgs e)
{
// homeGridView.Visible = true;
BindList();
}
protected string getSpecial(string price,object sale)
{
String special = "";
if (sale.ToString().CompareTo("True") == 0)
{
special = String.Format("{0:C}",double.Parse(price) * (1-discount));
}
return special;
}
protected void BindList()
{
//Creating an object for the 'PagedDataSource' for holding the data.
//PagedDataSource objPage = new PagedDataSource();
try
{
//open connection
openConnection();
//sql command
string columns = "*";
string SqlCommand = "Select " + columns + " from Books";
//create adapters and DataSet
OleDbDataAdapter myAdapter = new OleDbDataAdapter(SqlCommand, dbConn);
DataSet ds = new DataSet("bSet");
//create table
DataTable dt = new DataTable("Books");
myAdapter.Fill(ds, pageIndex, 9, "Books");
Response.Write("Page Index: "+pageIndex);
//create table data view
DataView dv = new DataView(ds.Tables["bTable"]);
booksDataList.DataSource = ds;
booksDataList.DataBind();
myAdapter.Dispose();
dbConn.Close();
}
catch (Exception ex)
{
Response.Write("Exception thrown in BindList()");
dbConn.Close();
throw ex;
}
}
public void openConnection()
{
string provider="Microsoft.Jet.OLEDB.4.0";
string dataSource = "C:/Documents and Settings/Owner/My Documents/Visual Studio 2005/WebSites/E-BookOnline/App_Data/BooksDB.mdb";
dbConn = new OleDbConnection("Provider =" + provider + ";" + "Data Source =" + dataSource);
dbConn.Open();
}
protected void nextClick(object sender, EventArgs e)
{
pageIndex=pageIndex+1;
Response.Write("In nextClick"+pageIndex);
BindList();
}
protected void prevClick(object sender, EventArgs e)
{
if (pageIndex > 0)
{
pageIndex=pageIndex-1;
BindList();
}
}
}
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class Home : System.Web.UI.Page
{
//Connection
OleDbConnection dbConn;
//discount that can be change by user using a gui interface
//CurrentPage
int pageIndex = 0;
double discount = 0.15 ;
protected void Page_Load(object sender, EventArgs e)
{
// homeGridView.Visible = true;
BindList();
}
protected string getSpecial(string price,object sale)
{
String special = "";
if (sale.ToString().CompareTo("True") == 0)
{
special = String.Format("{0:C}",double.Parse(price) * (1-discount));
}
return special;
}
protected void BindList()
{
//Creating an object for the 'PagedDataSource' for holding the data.
//PagedDataSource objPage = new PagedDataSource();
try
{
//open connection
openConnection();
//sql command
string columns = "*";
string SqlCommand = "Select " + columns + " from Books";
//create adapters and DataSet
OleDbDataAdapter myAdapter = new OleDbDataAdapter(SqlCommand, dbConn);
DataSet ds = new DataSet("bSet");
//create table
DataTable dt = new DataTable("Books");
myAdapter.Fill(ds, pageIndex, 9, "Books");
Response.Write("Page Index: "+pageIndex);
//create table data view
DataView dv = new DataView(ds.Tables["bTable"]);
booksDataList.DataSource = ds;
booksDataList.DataBind();
myAdapter.Dispose();
dbConn.Close();
}
catch (Exception ex)
{
Response.Write("Exception thrown in BindList()");
dbConn.Close();
throw ex;
}
}
public void openConnection()
{
string provider="Microsoft.Jet.OLEDB.4.0";
string dataSource = "C:/Documents and Settings/Owner/My Documents/Visual Studio 2005/WebSites/E-BookOnline/App_Data/BooksDB.mdb";
dbConn = new OleDbConnection("Provider =" + provider + ";" + "Data Source =" + dataSource);
dbConn.Open();
}
protected void nextClick(object sender, EventArgs e)
{
pageIndex=pageIndex+1;
Response.Write("In nextClick"+pageIndex);
BindList();
}
protected void prevClick(object sender, EventArgs e)
{
if (pageIndex > 0)
{
pageIndex=pageIndex-1;
BindList();
}
}
}