473,796 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

No record shown in gridview

Hello,
I am not able to see any records in GridView2. GridView2 is not shown.
I tried to print record count of datatable and it shows there is
records but nothing is shown in gridview2.

First I try to list products table in gridview1
I have added one column which shows select with hyperlink
When I click on select It adds that row from Products table to
datatable dt
for gridview1 GridView1_Selec tedIndexChanged event is written.
dt is stored in session

Can anybody please guide me what is wrong.

Windows XP
Visual Web Developer 2005
SQL Server 2000 (northwind db)

Thanks

///////////default.aspx/////////////////////
<%@ Page Language="C#" AutoEventWireup ="true"
CodeFile="Defau lt2.aspx.cs" Inherits="Defau lt2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView2" runat="server">
</asp:GridView>
-----------<br />
<asp:GridView ID="GridView1" runat="server" AllowPaging="Tr ue"
AllowSorting="T rue"
CellPadding="4" ForeColor="#333 333" GridLines="None "
OnSelectedIndex Changed="GridVi ew1_SelectedInd exChanged">
<FooterStyle BackColor="#507 CD1" Font-Bold="True"
ForeColor="Whit e" />
<Columns>
<asp:CommandFie ld ShowSelectButto n="True" />
</Columns>
<RowStyle BackColor="#EFF 3FB" />
<EditRowStyle BackColor="#246 1BF" />
<SelectedRowSty le BackColor="#D1D DF1" Font-Bold="True"
ForeColor="#333 333" />
<PagerStyle BackColor="#246 1BF" ForeColor="Whit e"
HorizontalAlign ="Center" />
<HeaderStyle BackColor="#507 CD1" Font-Bold="True"
ForeColor="Whit e" />
<AlternatingRow Style BackColor="Whit e" />
</asp:GridView>
<br />
--------------<br />

</div>

</form>
</body>
</html>

/////////////////////////////////////////////////

///////////default.aspx.cs///////////////
using System;
using System.Data;
using System.Configur ation;
using System.Collecti ons;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
using DataSet1TableAd apters;

public partial class Default2 : System.Web.UI.P age
{
DataTable dt;
DataSet ds;
protected void Page_Load(objec t sender, EventArgs e)
{

if (Session["ProductsTa ble"] == null)
{
dt = new DataTable();
ds = new DataSet();
ds.Tables.Add(d t);
Session["ProductsTa ble"] = ds;
}
else
{
ds = (DataSet)Sessio n["ProductsTa ble"];
dt = ds.Tables[0];
}

GridView2.Visib le = true;

//dt = new DataSet1.Produc tsDataTable();
if (!IsPostBack)
{
ProductsTableAd apter pta = new ProductsTableAd apter();
GridView1.DataS ource = pta.GetProducts ();
GridView2.DataS ource = ds;
Page.DataBind() ;
}
else
{
}
/*
ProductsTableAd apter pta = new ProductsTableAd apter();
GridView1.DataS ource = pta.GetProducts ();
GridView2.DataS ource = dt;
*/
}
protected void GridView1_Selec tedIndexChanged (object sender,
EventArgs e)
{

GridViewRow row = GridView1.Selec tedRow;
int productId;
productId = Convert.ToInt32 ( row.Cells[1].Text.ToString( ));
Response.Write( row.Cells[1].Text.ToString( ));
ProductsTableAd apter pta = new ProductsTableAd apter();
if (pta.GetProduct ById(productId) .Rows.Count 0)
{
dt.ImportRow(pt a.GetProductByI d(productId).Ro ws[0]);
}
Response.Write( "<br>"+ dt.Rows.Count.T oString());

}
}

///////////default.aspx.cs///////////////

Sep 27 '06 #1
0 1168

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

Similar topics

0
993
by: Edwin Knoppert | last post by:
I just tried the gridview's NEW linkbutton but nothing happens. Alternativly i made use of a separate detailsview on the same webpage and managed me to add a record fine. However, if i make use of the gridviews paging and due sorting effect the new record can be shown at any location. This is unwanted, i would prefer to let the gridview show the new fields for entering data just like the EDIT mode. On insert the paging should be on the...
0
1223
by: fig000 | last post by:
Hi, I'm trying to use the sqldatasource control and a detailsview to create a fully functional data entry screen; it's quite easy. I can see the strength of creating a master grid associated with a detailsview that gives you access to the record you choose in the grid. However one of the basic functions of this type of screen is the ability to enter a search term and have the grid display the record that is closest the search term....
10
5310
by: NH | last post by:
I have a girdview with paging enabled. How can I add a message in the footer to say "Viewing records 1-15 of 45" etc Thanks
0
1875
by: jeffmagill | last post by:
Hi Everybody, I'm really hoping that someone can help me out because I have spent too much time on this project already! Basically, I have a DetailsView that handles all the Edits for a GridView - each row has an edit button and clicking on this should trigger that record to be loaded into the DetailsView for editing. The problem is that the record never gets loaded into the DetailsView. Instead, the DetailsView always and only...
1
3699
by: JayD | last post by:
Here is the problem: Using asp.net 2.0 to create a web app with standard master table gridview and child detailsview with insert capability. SQL Server 2000 database on the backend. Using Visual Web Developer for front-end development. I want to insert new records in detailsview based on selected gridview record. All the fields in "INSERT" mode are blank, which is okay EXCEPT that I want the child ID to be that of the selected...
1
1822
by: Dica | last post by:
i need to allow the user to select a row from my dataGrid for editing. as such, i include the record ID in the first column and then extract like so when retrieving the record details: protected void gvLocations_edit(object sender, GridViewEditEventArgs e) { // load the record details into the edit fields // GridView gvRecord = (GridView)sender; string sThisRecord = gvRecord.Rows.Cells.Text; ...
0
966
by: Mike N. | last post by:
Greetings: I have a gridview control which contains several hundred thousand records. The user is able to sort by a multitude of fields. I want to be able to put in a search string for one of those fields and have the gridview go to that page and select that record. I don't want to filter the data, it's important that the gridview keep all of the records because I have the rownumber displayed as a ranking. In other words, each time...
2
1336
by: =?Utf-8?B?THVpZ2k=?= | last post by:
Hi all, is it possible, when a user select a record in a GridView (ASP.NET 2.0 - VS 2005) show only this record in this GridView and hidden all others records? Thanks a lot. -- Luigi
7
11062
by: =?Utf-8?B?SnVsaWEgQg==?= | last post by:
Hi all, this is a second post, so apologies, but I never had an answer to my first post (several weeks ago) and I really need some help. I'm using a .Net 2.0 Gridview which is populated using an ObjectDataSource which calls on a method in a class. This all works fine. The Gridview has a select button automatically generated. When the user presses this I want to be able to take the data from the selected record and use it. However...
0
9685
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
10242
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
10200
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
10021
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9061
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...
1
7558
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4127
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
3744
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.