No record shown in gridview

B

bhawin13

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_SelectedIndexChanged 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="Default2.aspx.cs" Inherits="Default2" %>

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled 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="True"
AllowSorting="True"
CellPadding="4" ForeColor="#333333" GridLines="None"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
<FooterStyle BackColor="#507CD1" Font-Bold="True"
ForeColor="White" />
<Columns>
<asp:CommandField ShowSelectButton="True" />
</Columns>
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True"
ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True"
ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<br />
--------------<br />

</div>

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

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

///////////default.aspx.cs///////////////
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DataSet1TableAdapters;

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

if (Session["ProductsTable"] == null)
{
dt = new DataTable();
ds = new DataSet();
ds.Tables.Add(dt);
Session["ProductsTable"] = ds;
}
else
{
ds = (DataSet)Session["ProductsTable"];
dt = ds.Tables[0];
}

GridView2.Visible = true;

//dt = new DataSet1.ProductsDataTable();
if (!IsPostBack)
{
ProductsTableAdapter pta = new ProductsTableAdapter();
GridView1.DataSource = pta.GetProducts();
GridView2.DataSource = ds;
Page.DataBind();
}
else
{
}
/*
ProductsTableAdapter pta = new ProductsTableAdapter();
GridView1.DataSource = pta.GetProducts();
GridView2.DataSource = dt;
*/
}
protected void GridView1_SelectedIndexChanged(object sender,
EventArgs e)
{

GridViewRow row = GridView1.SelectedRow;
int productId;
productId = Convert.ToInt32( row.Cells[1].Text.ToString());
Response.Write(row.Cells[1].Text.ToString());
ProductsTableAdapter pta = new ProductsTableAdapter();
if (pta.GetProductById(productId).Rows.Count > 0)
{
dt.ImportRow(pta.GetProductById(productId).Rows[0]);
}
Response.Write("<br>"+ dt.Rows.Count.ToString());

}
}

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top