How to create Temporary Table in ASP.Net using C#

How to create Temporary Table in ASP.Net using C#:



In this post we create a table by programmatically by C# code. Take grid control and bind dynamically created table in this gridviewcontrol.

Create Temporary Table by C#:

<%@ Page Language="C#" AutoEventWireup="true"
 CodeFile="tablebyCsharp.aspx.cs"
Inherits="tablebyCsharp" %>

<!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>

    <title>create Temporary Table in ASP.Net using C#</title>
</head>
<body>
    <form id="form1" runat="server">
    <div align="center">
        <h1>
            Temp data table in asp.net using c#</h1>
        <br />
        <%--bind this control by dymanic created table.--%>
        <asp:GridView ID="gird1" runat="server" >
            <HeaderStyle BackColor="Maroon" Font-Bold="true" ForeColor="White" />
        </asp:GridView>
    </div>
    </form>
</body>
</html>

Temporary Table in ASP.Net using C# code :

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 tablebyCsharp : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            createtable();
        }           
    }
    public void createtable()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("Cost_Id", typeof(Int32));
        dt.Columns.Add("Name", typeof(string));
        dt.Columns.Add("Address", typeof(string));
        dt.Rows.Add(1, "Parijat", "India");
        dt.Rows.Add(2, "Roz", "U.S.A");
        dt.Rows.Add(3, "Maqsood", "U.P.");
        dt.Rows.Add(4, "Parvez", "Pakistan");
        dt.Rows.Add(6, "Tinny", "Japan");
        dt.Rows.Add(7, "Mr. Song", "Chine");
        gird1.DataSource = dt;
        gird1.DataBind();
    }
}
How to create Temporary Table in ASP.Net using C#


Other asp.net related Post:

Comments

Popular posts from this blog