Monday, March 2, 2015

Create Temporary table dynamically in asp.net

Introduction: In this article today I am going to explain how to create Temporary table dynamically in asp.net
Description:


Html Markup Of page:
<asp:GridView ID="grdbook" runat="server">
        <HeaderStyle Font-Bold="true"/>
        </asp:GridView>


C# Code:
using System.Data;

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bindgrid();
        }
    }
    public void Bindgrid()
    {
        try
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("BookId", typeof(Int32));
            dt.Columns.Add("Book Name", typeof(string));
            dt.Columns.Add("Book price", typeof(int));
            dt.Rows.Add(1, "Kite Runner", 123);
            dt.Rows.Add(2, "ASP.Net MVC4", 150);
            dt.Rows.Add(3, "ASP.Net 3.5", 199);
            dt.Rows.Add(4, "ASP.Net 4", 299);
            dt.Rows.Add(5, "ASP.Net MVC5", 399);
            dt.Rows.Add(6, "ASP.Net", 149);
            grdbook.DataSource = dt;
            grdbook.DataBind();
        }
        catch (Exception ex)
        {
        }       
    }

VB Code:
Imports System.Data

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Bindgrid()
        End If
    End Sub
    Public Sub Bindgrid()
        Try
            Dim dt As New DataTable()
            dt.Columns.Add("BookId", GetType(Int32))
            dt.Columns.Add("Book Name", GetType(String))
            dt.Columns.Add("Book price", GetType(Integer))
            dt.Rows.Add(1, "Kite Runner", 123)
            dt.Rows.Add(2, "ASP.Net MVC4", 150)
            dt.Rows.Add(3, "ASP.Net 3.5", 199)
            dt.Rows.Add(4, "ASP.Net 4", 299)
            dt.Rows.Add(5, "ASP.Net MVC5", 399)
            dt.Rows.Add(6, "ASP.Net", 149)
            grdbook.DataSource = dt
            grdbook.DataBind()
        Catch ex As Exception
        End Try
    End Sub

Result:
Temporary table


  Is this article helpful for you?

If yes post your comment to appreciate my work and fell free to contact me. You can like me on Facebook, Google+, Linkedin and Twitter via hit on Follow us Button and also can get update follow by Email.

No comments:

Post a Comment