By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,719 Members | 1,811 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,719 IT Pros & Developers. It's quick & easy.

GridView not displaying data in browser on pressing button Go when bind to DataTable

P: n/a
I have created a GridView and dynamically added data to it by
creating a DataTable(as advised) and bound it with a reader. Then,
assigned the DataSource of GridView to DataTable. But even that aint
working as alternatively
assigned reader obj. to datasource of GridView. Here is the code for
the aspx.cs page: ( The reader surely cootains data as its HasRows
property is true). Plz help. Never got stuck this bad with a problem.
For more than two weeks.

protected void Button1_Click(object sender, EventArgs e)
{
// CustID->AccId->ATM-Id->Atm_TransID....
int AtmtransId=-1;
if (Session["CustomerId"]!=null)

AtmtransId=DataAccessLayer.ATMManager.getATMTransa ctionsID(Session["CustomerId"].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|\Banki ngDb.mdf;Integrated
Security=True;User Instance=True");
SqlCommand cmd = new SqlCommand(Query,sqlconnection);
cmd.Parameters.AddWithValue("@ATMTRANSID",Atmtrans Id);
GridView GridView1 = new GridView();
sqlconnection.Open();
// Fill the Data Reader
SqlDataReader reader=cmd.ExecuteReader();
//Create a DataTable object
DataTable dt=new DataTable();
//Load Data from Data Reader to DataTable object
dt.Load(reader);
//Fill the GridView Control
GridView1.DataSource = dt;
GridView1.DataBind();
reader.Close();
sqlconnection.Close();
}

May 8 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Couple suggestions:
1) Try the ASP.NET group, this is really not a C# language group question.
2) Get in the habit of wiring up any code you write that could *possibly*
cause an exception into a try / catch / finally block pattern.

When you do this, for debugging purposes you can do things like:

System.Diagnostics.Debug.WriteLine( ex.Message +ex.StackTrace);

on the "ex" Exception object inside the catch block and get a lot of very
useful information about what went wrong.

Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"weird0" wrote:
I have created a GridView and dynamically added data to it by
creating a DataTable(as advised) and bound it with a reader. Then,
assigned the DataSource of GridView to DataTable. But even that aint
working as alternatively
assigned reader obj. to datasource of GridView. Here is the code for
the aspx.cs page: ( The reader surely cootains data as its HasRows
property is true). Plz help. Never got stuck this bad with a problem.
For more than two weeks.

protected void Button1_Click(object sender, EventArgs e)
{
// CustID->AccId->ATM-Id->Atm_TransID....
int AtmtransId=-1;
if (Session["CustomerId"]!=null)

AtmtransId=DataAccessLayer.ATMManager.getATMTransa ctionsID(Session["CustomerId"].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|\Banki ngDb.mdf;Integrated
Security=True;User Instance=True");
SqlCommand cmd = new SqlCommand(Query,sqlconnection);
cmd.Parameters.AddWithValue("@ATMTRANSID",Atmtrans Id);
GridView GridView1 = new GridView();
sqlconnection.Open();
// Fill the Data Reader
SqlDataReader reader=cmd.ExecuteReader();
//Create a DataTable object
DataTable dt=new DataTable();
//Load Data from Data Reader to DataTable object
dt.Load(reader);
//Fill the GridView Control
GridView1.DataSource = dt;
GridView1.DataBind();
reader.Close();
sqlconnection.Close();
}

May 9 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.