In my opinion programming means thinking, and it is fun. My vision is to teach programming in more understandable manner to the students from rural background. I support programming for everyone

GridView Manual Implementation


Open VisualStudio => Select new Website=> give name to the website as GridView_Demo
Add a asp.net webpage to website Default.aspx
Add a Gridview to the page and put AutoGenerateColumns="False"
    <asp:GridView ID="GridView2" runat="server" BackColor="White"
        BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4"
        Width="691px" AutoGenerateColumns="False">
        <Columns>       
            <asp:BoundField HeaderText="Party Name" DataField="patName" />
            <asp:BoundField HeaderText="Party Id" DataField="patId" />
            <asp:BoundField HeaderText="Email" DataField="email" />
        </Columns>
        <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
        <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
        <PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
        <RowStyle BackColor="White" ForeColor="#330099" />
        <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
        <SortedAscendingCellStyle BackColor="#FEFCEB" />
        <SortedAscendingHeaderStyle BackColor="#AF0101" />
        <SortedDescendingCellStyle BackColor="#F6F0C0" />
        <SortedDescendingHeaderStyle BackColor="#7E0000" />
    </asp:GridView>

In code behind file put the fallowing code in page_load
            DataTable dt = new DataTable();
            DataColumn patName = new DataColumn("patName");
            DataColumn patId = new DataColumn("patId");
            DataColumn email = new DataColumn("email");
           
            dt.Columns.Add(patName);
            dt.Columns.Add(patId);
            dt.Columns.Add(email);
           
            DataRow row = null;
            foreach (string record in records)
            {
                string[] cols = record.Replace("||", "|").Split('|');
                if (cols.Length > 1)
                {
                    row = dt.NewRow();
                    row[patId] = cols[1].Trim();
                    row[patName] = cols[0].Trim();
                    row[email] = cols[2].Trim();
                    dt.Rows.Add(row);
                }
}
            GridView2.DataSource = dt;
            GridView2.DataBind();
The gridview in webpage will look like fallowing image:
Capture