How can I display data using GridView and Reader

W

weird0

Below is the code I wrote but it aint working.... :

It throws an exception on DataBind() statement that "the source does
not support server-side paging".

PLz Help. Really stuck.

protected void Button1_Click(object sender, EventArgs e)
{
int AtmtransId=-1;
if (Session["CustomerId"]!=null)
AtmtransId=DataAccessLayer.ATMManager.getATMTransactionsID(Session["Custome­
rId"].ToString(),AccNamesList.SelectedItem.Text);
string Query = "SELECT atmtrans_date AS Date,atmtrans_branch
AS Branch,atmtrans_type AS Type,atmtrans_amount AS Amount FROM
ATM_Transactions WHERE atmtrans_id=@ATMTRANSID";
SqlConnection sqlconnection = new SqlConnection(@"Data
Source=.
\SQLEXPRESS;AttachDbFilename=|DataDirectory|\BankingDb.mdf;Integrated
Security=True;User Instance=True");
SqlCommand cmd = new SqlCommand(Query,sqlconnection);
cmd.Parameters.AddWithValue("@ATMTRANSID",AtmtransId);
sqlconnection.Open();
SqlDataReader reader=cmd.ExecuteReader();
sqlconnection.Close();
GridView1.DataSource=reader;
GridView1.DataBind();
sqlconnection.Close();

}


GridView's AllowPaging Property is set to true with some function
defined to its corresponding property.
 
J

John Timney \(MVP\)

DataReader isn't the easiest choice for paging and sorting. This article
explains it all for you.

http://dotnetjunkies.com/Article/3F9C7FED-BFDB-49CC-BAF9-442079430EB2.dcik


Regards

John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog


Below is the code I wrote but it aint working.... :

It throws an exception on DataBind() statement that "the source does
not support server-side paging".

PLz Help. Really stuck.

protected void Button1_Click(object sender, EventArgs e)
{
int AtmtransId=-1;
if (Session["CustomerId"]!=null)
AtmtransId=DataAccessLayer.ATMManager.getATMTransactionsID(Session["Custome­
rId"].ToString(),AccNamesList.SelectedItem.Text);
string Query = "SELECT atmtrans_date AS Date,atmtrans_branch
AS Branch,atmtrans_type AS Type,atmtrans_amount AS Amount FROM
ATM_Transactions WHERE atmtrans_id=@ATMTRANSID";
SqlConnection sqlconnection = new SqlConnection(@"Data
Source=.
\SQLEXPRESS;AttachDbFilename=|DataDirectory|\BankingDb.mdf;Integrated
Security=True;User Instance=True");
SqlCommand cmd = new SqlCommand(Query,sqlconnection);
cmd.Parameters.AddWithValue("@ATMTRANSID",AtmtransId);
sqlconnection.Open();
SqlDataReader reader=cmd.ExecuteReader();
sqlconnection.Close();
GridView1.DataSource=reader;
GridView1.DataBind();
sqlconnection.Close();

}


GridView's AllowPaging Property is set to true with some function
defined to its corresponding property.
 

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

Top