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///////////////