HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Single dimension array example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="gvSingDimensionalArray" runat="server" Width="500px" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="StudentName" HeaderText="StudentName" ItemStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
</div>
</form>
</body>
</html>
CODE BEHIND
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 TestDesign_SingleDimensionArray : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGridview();
}
}
private void BindGridview()
{
//Declaring single dimensional array
string[] StudentName = new string[5];
StudentName[0] = "Fuzlul Roman";
StudentName[1] = "Iqbal Hossain";
StudentName[2] = "Jabed Hossain";
StudentName[3] = "Noor Mohammad";
StudentName[4] = "Khorshed Alam";
DataTable dt = new DataTable();
dt.Columns.Add("StudentName");
for (int i = 0; i < StudentName.Count(); i++)
{
dt.Rows.Add();
dt.Rows[i]["StudentName"] = StudentName[i].ToString();
}
gvSingDimensionalArray.DataSource = dt;
gvSingDimensionalArray.DataBind();
}
}