473,508 Members | 2,400 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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
1 2745
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
14784
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
1
9331
by: Miguel Dias Moura | last post by:
Hello, I have a GridView in my page which is created in runtime. It works fine. My page has 2 Asp Buttons: - The HIDE button makes GridView.Visible = False; - The SHOW button makes...
5
6408
by: sutphinwb | last post by:
Hi - This could be a simple question. When I relate two tables in a datasetet, how do I get that relation to show up in a GridView? The only way I've done it, is to create a separate table in the...
3
1969
by: Richard Carpenter | last post by:
I have a simple winform with a customers combobox, a "get orders" button and an orders grid. Due to other requirements, I have implemented the form to allow the user to select a customer from the...
1
5205
by: joechipubik | last post by:
I have a GridView in a FormView that has as its datasource a DataTable that is stored in the session cache. When I first load the page the GridView is displayed correctly, but on subsequent loads...
4
26681
by: Tomasz Jastrzebski | last post by:
Hello Everyone, I have a GridView control bound to a plain DataTable object. AutoGenerateEditButton is set to true, Edit button gets displayed, and RowEditing event fires as expected.
1
7844
by: spitapps | last post by:
In a traditional gridview control the items inserted(bind) into the control are rows and the data is in columns. I have a customer who wants the data fields as rows and the columns as the items...
1
3609
by: ist | last post by:
Hi, I am trying to create a Session-Wide, Disconnected, Updatable DataTable (or DataSet) object and use it through an ASP.NET GridView. The scenario is this: 1. When the page is first loaded,...
4
10988
by: Craig Buchanan | last post by:
I dynamically add data-bound templates to a gridview in my ascx control. while this works correctly when the gridview is databound to the datatable, i'm having issues on postback. i would like...
0
7114
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7034
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5045
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1544
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.