Friday, 27 March 2015

GridView To Another Page GridView Send Values Using DataSet or DataTable With Session In Asp.Net C#

GridView To Another Page GridView Send Values

One GridView Display Values Send To Another Page GridView  Using DataTable Or DataSet With Pass Session & Get Another Page Page_Load  Get Session bind To GridView In Asp.Net C#.

                                DEMO

                       



HTML CODING(First Page)

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table><tr><td></td><td><asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" >
     <HeaderStyle BackColor="#FF3300" />
            <RowStyle BackColor="Silver" />
            <AlternatingRowStyle BackColor="#9999FF" />
</asp:GridView></td></tr>
            <tr><td colspan="2">  <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Send Next Page" /></td></tr>
        </table>

        <br />
    </div>
    </form>
</body>
</html>

  
           HTML CODING(Second Page)


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> </title>
</head>
<body>
    <form id="form1" runat="server">
      <div>
           
         <table><tr><td> </td><td>   <asp:GridView ID="GridView1" runat="server">

               <AlternatingRowStyle BackColor="#9999FF" />

                 <HeaderStyle BackColor="#FF3300" />
                      <RowStyle BackColor="#FF99FF" />           
            </asp:GridView>
             </td></tr></table>  
        </div>
    </form>
</body>

</html>



          C# CODING(First Page)


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;
using System.Data.SqlClient;


public partial class Default4 : System.Web.UI.Page
{
    DataSet ds1;

    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["dbcon"].ToString());
        con.Open();

        SqlCommand cmd = new SqlCommand("select * from country", con);

        SqlDataAdapter adp = new SqlDataAdapter(cmd);
         ds1 = new DataSet();
        adp.Fill(ds1);

        GridView1.DataSource = ds1;
        GridView1.DataBind();

    }  
    protected void Button1_Click(object sender, EventArgs e)
    {
        Session["ds"] = ds1;
        Response.Redirect("Default3.aspx");
    }
}
  

                C# CODING(Second Page)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;


public partial class Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        DataSet ds2 = new DataSet();
        ds2 = (DataSet)Session["ds"];

        GridView1.DataSource = ds2;
        GridView1.DataBind();
      
    }
           
}



















0 comments:

Post a Comment