Introduction – Create Temporary Table In ASP.Net
In this post I will show you how you can create a temporary table dynamically in ASP.Net using C# or you can say how you can create a temporary table in ASP.Net and bind it with gridview control using C#.
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="grid" runat="server"></asp:GridView> <br /> <asp:Button ID="btn1" runat="server" Text="Click" OnClick="btn1_Click" /> </div> </form> </body> </html>
Default.aspx.cs
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Configuration; using System.Data; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btn1_Click(object sender, EventArgs e) { DataTable test = GetTable(); } private DataTable GetTable() { DataTable test = new DataTable(); test.Columns.Add("name", typeof(string)); test.Columns.Add("email", typeof(string)); test.Rows.Add("Paras", "parasbabbar@parasbabbar.in"); test.Rows.Add("Ajay", "ajay@outlook.com"); grid.DataSource = test; grid.DataBind(); return test; } }