Home > ASP.NET > How to bind gridview with datatable in asp.net with c# without using the database



How to bind gridview with datatable in asp.net with c# without using the database

In this article we have described how to bind Gridview in asp.net with C# without using the database.


In this article we have described how to use gridview with the datatable in asp.net with C# using Mysql.

 

About Gridview

Gridview is a control in asp.net. Gridview is a very popular and useful control in C#. We can specify custom columns and styles. Gridview automatically binds to and displays data from a data source control .

 

Required Namespaces:

you will need to use the following namespaces.

using System.Data;

using System.Configuration;

 

Aspx page

We have used the gridview code below. You can have a look at it and learn.

<html xmlns="">

<head runat="server">

   <title>HOW TO USE DATATABLE IN ASP.NET</title>

</head>

<body>

   <form id="form1" runat="server">

       <asp:GridView ID="gvUsers" calss="table table-bordered responsive-table" AutoGenerateColumns="true" runat="server">

       </asp:GridView>

   </form>

</body>

</html>

 

C#

We have explained below C# code and added the examples of some user information in this article .You can have a look at it and learn.

protected void Page_Load(object sender, EventArgs e)

   {

       DataTable dt = new DataTable();

       dt.Columns.Add("CustomerID"typeof(int));

       dt.Columns.Add("Customer Names "typeof(string));

       dt.Columns.Add("Address"typeof(string));

       dt.Rows.Add(new object[] { 1, "RJboy""India" });

       dt.Rows.Add(new object[] { 2, "Michael""UK" });

       dt.Rows.Add(new object[] { 3, "Abhi""India" });

       dt.Rows.Add(new object[] { 4, "kevin""USA", });

       dt.Rows.Add(new object[] { 5, "donald""brazil" });

       gvCustomers.DataSource = dt;

       gvCustomers.DataBind();

   }

 



Note: All contents are copyright of their authors.



Comments



Leave a Reply

Comment:*
Email ID:*


Name:*