Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > No record shown in gridview

Reply
Thread Tools

No record shown in gridview

 
 
bhawin13
Guest
Posts: n/a
 
      09-27-2006
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_SelectedIndexCha nged">
<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///////////////

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
IP Address, MX Record, A Record Question K.J. 44 Cisco 2 09-06-2006 05:14 PM
You cannot add or change a record because a related record is required in table 'lok" André ASP .Net 0 06-25-2006 01:30 PM
Retrieving Record Key while creating the record. =?Utf-8?B?SnVzdGlu?= ASP .Net 4 10-05-2004 08:11 PM
" Invalid Disk Table in Boot Record - Boot Record could not be repaired " reply@newsgroup.please Computer Support 2 12-01-2003 05:37 AM
NOT SHOWN. The page is not shown until refresh it ! Mete Akalýn ASP General 1 07-25-2003 11:28 AM



Advertisments