473,853 Members | 1,957 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(o bject sender, EventArgs e)
{
// CustID->AccId->ATM-Id->Atm_TransID... .
int AtmtransId=-1;
if (Session["CustomerId "]!=null)

AtmtransId=Data AccessLayer.ATM Manager.getATMT ransactionsID(S ession["CustomerId "].ToString(),Acc NamesList.Selec tedItem.Text);
string Query = "SELECT atmtrans_date AS Date,atmtrans_b ranch
AS Branch,atmtrans _type AS Type,atmtrans_a mount AS Amount FROM
ATM_Transaction s WHERE atmtrans_id=@AT MTRANSID";
SqlConnection sqlconnection = new SqlConnection(@ "Data Source=.
\SQLEXPRESS;Att achDbFilename=| DataDirectory|\ BankingDb.mdf;I ntegrated
Security=True;U ser Instance=True") ;
SqlCommand cmd = new SqlCommand(Quer y,sqlconnection );
cmd.Parameters. AddWithValue("@ ATMTRANSID",Atm transId);
GridView GridView1 = new GridView();
sqlconnection.O pen();
// Fill the Data Reader
SqlDataReader reader=cmd.Exec uteReader();
//Create a DataTable object
DataTable dt=new DataTable();
//Load Data from Data Reader to DataTable object
dt.Load(reader) ;
//Fill the GridView Control
GridView1.DataS ource = dt;
GridView1.DataB ind();
reader.Close();
sqlconnection.C lose();
}

May 8 '07 #1
1 2770
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.Diagnost ics.Debug.Write Line( 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(o bject sender, EventArgs e)
{
// CustID->AccId->ATM-Id->Atm_TransID... .
int AtmtransId=-1;
if (Session["CustomerId "]!=null)

AtmtransId=Data AccessLayer.ATM Manager.getATMT ransactionsID(S ession["CustomerId "].ToString(),Acc NamesList.Selec tedItem.Text);
string Query = "SELECT atmtrans_date AS Date,atmtrans_b ranch
AS Branch,atmtrans _type AS Type,atmtrans_a mount AS Amount FROM
ATM_Transaction s WHERE atmtrans_id=@AT MTRANSID";
SqlConnection sqlconnection = new SqlConnection(@ "Data Source=.
\SQLEXPRESS;Att achDbFilename=| DataDirectory|\ BankingDb.mdf;I ntegrated
Security=True;U ser Instance=True") ;
SqlCommand cmd = new SqlCommand(Quer y,sqlconnection );
cmd.Parameters. AddWithValue("@ ATMTRANSID",Atm transId);
GridView GridView1 = new GridView();
sqlconnection.O pen();
// Fill the Data Reader
SqlDataReader reader=cmd.Exec uteReader();
//Create a DataTable object
DataTable dt=new DataTable();
//Load Data from Data Reader to DataTable object
dt.Load(reader) ;
//Fill the GridView Control
GridView1.DataS ource = dt;
GridView1.DataB ind();
reader.Close();
sqlconnection.C lose();
}

May 9 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
14826
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 want to look at that data and filter it based on what is in it. I know that this could have been done with data sets and data views in asp.net 1.1 but how is this done now in asp.net 2.0?
1
9363
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 GridView.Visible = True. I press HIDE and the GridView disappears as expected. After it I press SHOW and the GridView doesn't show.
5
6462
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 dataset with a join query for the GetData() select method. I use ObjectDataStore to couple the GridView with the table adapter on the dataset. If I point the ODS at the child table, the GridView will bind to the "normal" select and I end up...
3
1989
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 combobox and click the "get orders" button to refresh the gridview with the selected customer's orders, via a GetDataByCustomerID stored procedure. The underlying Orders table includes, among others, three boolean columns and one particular...
1
5219
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 the GridView does not display. I've debugged the DataTable and even when it has data and is bound to the GridView, when the page loads the GridView is not displayed. I set the datasource and then bind the GridView. I've tried disabling the...
4
26716
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
7858
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 being inserted(bind). I have never seen a gridview control displayed in this fashion but would like to use a control to accomplish this, so I am wondering if this is possible or if someone has an idea on how to accomplish this. Thanks. normal...
1
3627
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, connect to DB, get data, fill DataTable. 2. Bind DataTable to GridView. Set DataTable as a Session object. 3. User continues navigating page, but after first load, no more DB
4
11020
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 to iterate thru the gridview's rows, examine the databound controls, then perform a database action. for some reason, i can't find the controls. i have a two templates: one that uses a label the other uses a textbox to display data. when the...
0
9898
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9748
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10670
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10735
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9506
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5736
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5934
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4549
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 we have to send another system
2
4143
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.