How to use DataTable in ASP.NET

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        <asp:Button ID="Button1" runat="server" Height="37px" onclick="Button1_Click"
            Text="Bind Gridview" Width="130px" />
        <br />
    <asp:GridView ID="GridView1" runat="server">

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

public partial class Default4 : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)

    protected void Button1_Click(object sender, EventArgs e)
        using (SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True"))
            SqlCommand cmd = new SqlCommand("select * from [mytab]", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
                       GridView1.DataSource = dt;


How to use DataTable in ASP.NET

How to use DataTable in ASP.NET How to use DataTable in ASP.NET Reviewed by Jacob Lefore on September 18, 2013 Rating: 5

No comments