Posted by : Anwar Hossain
Category : State Management in ASP C #

stroe datatable in session retrive display session vlaues in ASP.Net C #

Dear viewer's in this tutorial I will explain how to store datatable in session and can be retrived and displayed this session vlaues in ASP.Net C # as requirment. In this example I have created a datatable and after filling data to datatable then I have stored datatable in session .For clear undestanding I have also used a gridview to display the session vlaues.

store datatable in session retrive to display


HTML


<asp:GridView ID="Studentlist" CssClass="Grid" runat="server"

            AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333"

            GridLines="None" Width ="55%" >

            <AlternatingRowStyle BackColor="White" />

            <Columns>

                <asp:BoundField DataField="StudentName" HeaderText="StudentName" />

                <asp:BoundField DataField="Address" HeaderText="Address" />

                <asp:BoundField DataField="Phone" HeaderText="Phone" />

                <asp:BoundField DataField="JoingDate" HeaderText="JoingDate" />

              

            </Columns>

            <EditRowStyle BackColor="#7C6F57" />

            <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />

            <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />

            <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />

            <RowStyle BackColor="#E3EAEB" />

            <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />

            <SortedAscendingCellStyle BackColor="#F8FAFA" />

            <SortedAscendingHeaderStyle BackColor="#246B61" />

            <SortedDescendingCellStyle BackColor="#D4DFE1" />

            <SortedDescendingHeaderStyle BackColor="#15524A" />

        </asp:GridView>


CODE BEHIND


using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

 

public partial class StoreDataTableValueinSession : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

 

        Session["StudentList"] = GetStudentList();

        Studentlist.DataSource = Session["StudentList"];

        Studentlist.DataBind();

 

 

    }

  

    static DataTable GetStudentList()

    {

 

        //Created virtual data Storage

 

        DataTable table = new DataTable();

        table.Columns.Add("StudentName", typeof(string));

        table.Columns.Add("Address", typeof(string));

        table.Columns.Add("Phone", typeof(string));

        table.Columns.Add("JoingDate", typeof(DateTime));

 

 

        // Now have created some row to fill the the datatable

 

        table.Rows.Add("Samima Nasim", "Dhaka", "01856587548", "11/5/2010");

        table.Rows.Add("Ahsanul Kabir", "Chittagong", "01856587548", "12/ 5/2204");

        table.Rows.Add("Nirub Ashasan", "Sylhet", "01856587544", "11/10/ 2008");

        table.Rows.Add("Zaman Ahmed", "Rajsahi", "01856587878", "11 /15/ 2003");

        table.Rows.Add("Habibur Rahman", "Barisal", "01856587548", "11 /5 / 2010");

 

        return table;

    }

 

  

}

 


Output


store-data-table-value-in-Chsarp



Realted Article Headline

How to Pass Query String parameter From DataList
Query String Example in ASP.NET C#
How to increase session time in ASP.Net C#
stroe datatable in session retrive display session vlaues in ASP.Net C #
How to clear Session state in ASP.NET C#
Session state in ASP.NET C#

Article Category

How to create asp.net control dynamically
Learn HTML for beginner
DataList example in C Sharp
Mail sending in asp.net c#
State Management in ASP C #
Basic sql tutorial for Beginner
DataTable example in ASP.Net C#
How to use LINQ in ASP.NET C#
asp.net c # basic tutorial
How to use ajax toolkit in asp.net C#
How to use different types of validation control using asp.net c#
How to use grid view in asp.net c#
Protected by Copyscape Online Plagiarism Detection