I just explain how to create data table and display item in datatable using gridview technique;
on the back end you write this code which is C#using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data;
namespace WebApplication1
{
public partial class gridviewsample : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGridView();
}
}
private void BindGridView()
{
string[] array = { "pakistan", "china", "indonasia", "malaysia", "germany", "dutch", "italt" };
DataTable dt= new DataTable();
dt.Columns.Add("names");
int count=0;
for (int i = 0; i <= array.Count(); i++)
{
dt.Rows.Add();
dt.Rows[i]["names"] = array[i].ToString();
count++;
if (count == array.Count())
{
break;
}
}
gvarray.DataSource = dt;
gvarray.DataBind();
}
}
}
on front i.e on ASP write this one:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="gridviewsample.aspx.cs" Inherits="WebApplication1.gridviewsample" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Grid view with Array list</title>
<style type="text/css">
gridview
{
font-family:Lucida Handwriting;
font-size:10pt;
font-weight:normal;
color:Navy;
width:auto;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:gridview ID="gvarray" runat="server" CssClass="Gridview" AutoGenerateColumns="false" HeaderStyle-BackColor="Brown" HeaderStyle-ForeColor="White" Caption="array wise grid list">
<Columns>
<asp:BoundField DataField="names" HeaderText="names" /></Columns>
</asp:gridview>
</div>
</form>
</body>
</html>