No record shown in gridview

Discussion in 'ASP .Net' started by bhawin13, Sep 27, 2006.

  1. bhawin13

    bhawin13 Guest

    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///////////////
    bhawin13, Sep 27, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SnVzdGlu?=

    Retrieving Record Key while creating the record.

    =?Utf-8?B?SnVzdGlu?=, Oct 4, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    623
    =?Utf-8?B?SnVzdGlu?=
    Oct 5, 2004
  2. André
    Replies:
    0
    Views:
    3,730
    André
    Jun 25, 2006
  3. MRW
    Replies:
    0
    Views:
    366
  4. THurkmans
    Replies:
    2
    Views:
    591
  5. Mete Akalýn
    Replies:
    1
    Views:
    399
    Mete Akalýn
    Jul 25, 2003
Loading...

Share This Page