We will learn here how to bind controls with data without a database and how to handle total sum of a column on controls.
Also read:
Initial Chamber
Step 1
Open your Visual Studio and create an empty website then provide a suitable name such as
GridViewColumnAdd.
Step 2In Solution Explorer you will get your empty website, then add some web forms.
GridViewColumnAdd (your empty website). Right-click and select Add New Item Web Form. Name it
GridViewColumnAdd.aspx.
Design ChamberStep 3Open the GridViewColumnAdd.aspx file and write some code for the design of the application.
Choose the control from the toolbox and provide your design page like:
- <form id="form1" runat="server">
- <div>
- <asp:GridView ID="GridView1" runat="server" AlternatingRowStyle-BackColor="Wheat" ShowFooter="true">
- </asp:GridView>
- </div>
- </form>
Here I've enabled the "ShowFooter" property of GridView to show the total sum of a column in the footer.
Here I've designed the GridView Control and used some property as in the following.
Design Page
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridViewColumnAdd.aspx.cs" Inherits="GridViewColumnAdd" %>
-
- <!DOCTYPE html>
-
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <asp:GridView ID="GridView1" runat="server" AlternatingRowStyle-BackColor="Wheat" ShowFooter="true">
- </asp:GridView>
- </div>
- </form>
- </body>
- </html>
Your design looks as in the following:
Figure 1Code ChamberStep 4In the code chamber we will write some code so that our application works.
Add the following
namespaces to the namespace section of your code behind page:
- 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;
Now your page looks as in the following.
Code behind Page
OutputFigure 2I hope you liked this. Have a good day. Thank you for reading.