Create Temporary table dynamically and bind to Gridview in - Free Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server,WCF,Entity framework snippets and tutorial

Create Temporary table dynamically and bind to Gridview in

Introduction: In this article today we will learn how to Create Temporary table dynamically and bind to Gridview in

Temporary table

Html Markup Of page:
<asp:GridView ID="grduser" runat="server" AutoGenerateColumns="false">
        <HeaderStyle Font-Bold="true"/>
      <asp:BoundField DataField="UserId" HeaderText="Id" ItemStyle-Width="30" ItemStyle-HorizontalAlign="Center"/>
        <asp:BoundField DataField="UserName" HeaderText="UserName" ItemStyle-Width="150" ItemStyle-HorizontalAlign="Center"/>   
        <asp:imagefield alternatetext="no image" headertext="Profile Image" dataimageurlfield="Profileimage" ControlStyle-Width="120" ControlStyle-Height ="100"  />   

C# Code:
using System.Data;

protected void Page_Load(object sender, EventArgs e)
    public void Bindgrid()
        DataTable dt = new DataTable();
        dt.Columns.Add("UserId", typeof(Int32));
        dt.Columns.Add("UserName", typeof(string));
        dt.Columns.Add("Profileimage", typeof(string));

        DataRow dr = dt.NewRow();
        dr["UserId"] = 1;
        dr["Profileimage"] = ResolveUrl("~/images/vs.jpg");
        dr["UserName"] = "Vijay";

        DataRow dr1 = dt.NewRow();
        dr1["UserId"] =2;
        dr1["Profileimage"] = ResolveUrl("~/images/download.jpg");
        dr1["UserName"] = "Rohan";

        DataRow dr2 = dt.NewRow();
        dr2["UserId"] = 3;
        dr2["Profileimage"] = ResolveUrl("~/images/cr.jpg");
        dr2["UserName"] = "John";
        grduser.DataSource = dt;

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
        End If
    End Sub
    Public Sub Bindgrid()
        Dim dt As New DataTable()
        dt.Columns.Add("UserId", GetType(Int32))
        dt.Columns.Add("UserName", GetType(String))
        dt.Columns.Add("Profileimage", GetType(String))

        Dim dr As DataRow = dt.NewRow()
        dr("UserId") = 1
        dr("Profileimage") = ResolveUrl("~/images/vs.jpg")
        dr("UserName") = "Vijay"

        Dim dr1 As DataRow = dt.NewRow()
        dr1("UserId") = 2
        dr1("Profileimage") = ResolveUrl("~/images/download.jpg")
        dr1("UserName") = "Rohan"

        Dim dr2 As DataRow = dt.NewRow()
        dr2("UserId") = 3
        dr2("Profileimage") = ResolveUrl("~/images/cr.jpg")
        dr2("UserName") = "John"
        grduser.DataSource = dt
    End Sub

  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.

What do you think about this article?

If you found this article useful, please share and follow on Facebook, Twitter, Google Plus and other social media websites. To get free updates subscribe to newsletter. Please put your thoughts and feedback in comments section.