DataTable Dynamically Create And Bind To GridView in Asp.Net C#

DataTable Dynamically Create And Bind To GridView 


DataTable Values Create Dynamically And Bind To Gridview For Temporary Table Values in Asp.Net C#.


                       C# CODING


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class RemoveRow : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
        }
    }
    protected void Bind()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("Sno", typeof(int32));
        dt.Columns.Add("Name", typeof(string));
        dt.Columns.Add("City", typeof(string));

      
        dt.Rows.Add("1", "AAA", "Mumbai");
        dt.Rows.Add("2", "BBB", "New Delhi");
        dt.Rows.Add("3", "CCC", "Kolkata");
        dt.Rows.Add("4", "DDD", "Chennai");
        dt.Rows.Add("5", "EEE", "Bangalore");

     
        GridView2.DataSource = dt;
        GridView2.DataBind();
    }

   

0 comments:

Post a Comment