Web
Analytics
Custom Data Table in asp.net Using C# - Tutorial

For Consultation : +91 9887575540

Stay Connected :

DataTableEx.aspx:

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

<!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=”GridView1″ runat=”server”></asp:GridView>
</div>

</form>
</body>
</html>

DataTableEx.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;

public partial class DataTableex : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
DataTable dt = new DataTable(“Employee”);
dt.Columns.Add(“EmpId”, typeof(int));
dt.Columns.Add(“EmployeeName”, typeof(string));
DataRow dr = dt.NewRow();
dr[“EmpId”] = 1;
dr[“EmployeeName”] = “Yogesh”;
dt.Rows.Add(dr);
DataRow dr1 = dt.NewRow();
dr1[“EmpId”] = 2;
dr1[“EmployeeName”] = “Vikas”;
dt.Rows.Add(dr1);

GridView1.DataSource = dt;
GridView1.DataBind();

}
}
}

 

Download Source Code

Select your currency