
June 1, 2015 09:29 by
Peter
European Windows and ASP.NET Spotlight Hosting Partner in Europe, HostForLIFE.eu, has announced the availability of new hosting plans that are optimized for the latest update of the Drupal 7.37 hosting technology.

HostForLIFE.eu hosts its servers in top class data centers that is located in Amsterdam (NL), London (UK), Paris (FR), Frankfurt(DE) and Seattle (US) to guarantee 99.9% network uptime. All data center feature redundancies in network connectivity, power, HVAC, security, and fire suppression. All hosting plans from HostForLIFE.eu include 24×7 support and 30 days money back guarantee. The customers can start hosting our Drupal site on our environment from as just low €3.00/month only.
Drupal is an open source content management platform powering millions of websites and applications. Thousands of add-on modules and designs let you build any site you can imagine. Drupal 7.37 Includes bug fixes and small API/feature improvements only (no major new functionality); major, non-backwards-compatible new features are only being added to the forthcoming Drupal 8.0 release. If you are looking for the right Windows ASP.NET Hosting provider that support Drupal 7.37, we are the right choice for you.
The 7.37 update also includes fixed a regression in Drupal 7.36 which caused certain kinds of content types to become disabled if we were defined by a no-longer-enabled module, removed a confusing description regarding automatic time zone detection from the user account form (minor UI and data structure change), allowed custom HTML tags with a dash in the name to pass through filter_xss() when specified in the list of allowed tags, allowed hook_field_schema() implementations to specify indexes for fields based on a fixed-length column prefix (rather than the entire column), as was already allowed in hook_schema() implementations, fixed PDO exceptions on PostgreSQL when accessing invalid entity URLs, added a sites/all/libraries folder to the codebase, with instructions for using it and added a description to the "Administer text formats and filters" permission on the Permissions page (string change).
HostForLIFE have hosted large numbers of websites and blogs until now. Our clients come from diverse backgrounds from all sectors of the economy. HostForLIFE.eu clients are specialized in providing supports for Drupal for many years. We are glad to provide support for European Drupal 7.37 hosting users with advices and troubleshooting for our client website when necessary.
HostForLIFE.eu is a popular online Windows based hosting service provider catering to those people who face such issues. The company has managed to build a strong client base in a very short period of time. It is known for offering ultra-fast, fully-managed and secured services in the competitive market. Our powerful servers are especially optimized and ensure Drupal 7.37 performance. We have best data centers on three continent, unique account isolation for security, and 24/7 proactive uptime monitoring.
For more information about this new product, please visit http://hostforlife.eu/European-Drupal-737-Hosting
About HostForLIFE.eu
HostForLIFE.eu is an European Windows Hosting Provider which focuses on the Windows Platform only. HostForLIFE.eu deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.
HostForLIFE.eu is awarded Top No#1 SPOTLIGHT Recommended Hosting Partner by Microsoft (see http://www.asp.net/hosting/hostingprovider/details/953). Our service is ranked the highest top #1 spot in several European countries, such as: Germany, Italy, Netherlands, France, Belgium, United Kingdom, Sweden, Finland, Switzerland and other European countries. Besides this award, we have also won several awards from reputable organizations in the hosting industry and the detail can be found on our official website.

May 29, 2015 07:48 by
Peter
In the world of network encryption is one of the very important idea to secure your users' information from outside hackers. usually once user input any password related field its getting encrypted and so put that encrypted password into database. And within the case of retrieving there are 2 process are there. You will encrypt the imputing password and match it with the field in database otherwise you can decrypt the keep password and match it with the input. I thing first one is much better and less time consuming.

So, how to encrypt your inputted password field. The most common encryption technique is MD5. Here in this example I'll show you ways to encrypt a string into an encrypted password using MD5 in ASP.NET using C#. Create a new project and add a new WebForm to start your encrypted application. in the ASPX page add a new TextBox. Create a TextChange event and on the AutoPostBack property of the TextBox.
Write the following code, in the ASPX page:
<form id="form1" runat="server">
<div>
<asp:textbox autopostback="True" id="TextBox1" ontextchanged="TextBox1_TextChanged" runat="server"></asp:textbox>
Encrypted password :
<asp:label id="Label1" runat="server" text=""></asp:label>
</div>
</form>
Write the following code In the C# page:
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Security.Cryptography;
using System.Text;
using System;
namespace md5
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
Byte[] ePass;
UTF8Encoding encoder = new UTF8Encoding();
ePass = md5Hasher.ComputeHash(encoder.GetBytes(TextBox1.Text));
Label1.Text = Convert.ToBase64String(ePass);
}
}
}
In the Label1 you'll see the encrypted password. simply place the ePass into the database to store as an encrypted password. Your encryption is over. I hope it works for you!
Free ASP.NET 5 Hosting
Try our Free ASP.NET 5 Hosting today and your account will be setup soon! You can also take advantage of our Windows & ASP.NET Hosting support with Unlimited Domain, Unlimited Bandwidth, Unlimited Disk Space, etc.


May 25, 2015 07:48 by
Peter
Today I'll show you the way to make a search in GridView in ASP.NET using C#. You'll do it normally getting a ASP command button and run a query to get the value in a GridView. It'll refresh the page every time. You'll stop this by adding an UpdatePanel but the time taking will be more or less same. however here I'll use quickseacrch.js to search within a GridView. To do this produce a new project and add a new web form in your Visual Studio. In the aspx file write the following code to proceed.

<form id="form1" runat="server">
<asp:gridview autogeneratecolumns="False" headerstyle-backcolor="#3AC0F2" headerstyle-forecolor="White" id="GridView1" ondatabound="OnDataBound" runat="server">
<columns>
<asp:templatefield headertext="Name">
<itemtemplate>
<asp:label id="Label1" runat="server" text="<%# Eval("Name") %>"></asp:label>
</itemtemplate>
</asp:templatefield>
</columns>
</asp:gridview>
<script type="text/javascript">
$(function () {
$('.search_textbox').each(function (i) {
$(this).quicksearch("[id*=GridView1] tr:not(:has(th))", {
'testQuery': function (query, txt, row) {
return $(row).children(":eq(" + i + ")").text().toLowerCase().indexOf(query[0].toLowerCase()) != -1;
}
});
});
});
</script>
</form>
Now, in the head section add a script tag to do this js function:
<script type="text/javascript">
$(function () {
$('.search_textbox').each(function (i) {
$(this).quicksearch("[id*=GridView1] tr:not(:has(th))", {
'testQuery': function (query, txt, row) {
return $(row).children(":eq(" + i + ")").text().toLowerCase().indexOf(query[0].toLowerCase()) != -1;
}
});
});
});
</script>
In the CS page write the following code:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[1] {new DataColumn("Name", typeof(string))});
dt.Rows.Add("Peter");
dt.Rows.Add("Scott");
dt.Rows.Add("Rebecca");
dt.Rows.Add("Suzan");
dt.Rows.Add("Tom");
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void OnDataBound(object sender, EventArgs e)
{
GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
for (int i = 0; i < GridView1.Columns.Count; i++)
{
TableHeaderCell cell = new TableHeaderCell();
TextBox txtSearch = new TextBox();
txtSearch.Attributes["placeholder"] = GridView1.Columns[i].HeaderText;
txtSearch.CssClass = "search_textbox";
cell.Controls.Add(txtSearch);
row.Controls.Add(cell);
}
GridView1.HeaderRow.Parent.Controls.AddAt(1, row);
}
Finally, run the code. Hope it works!
Free ASP.NET 5 Hosting
Try our Free ASP.NET 5 Hosting today and your account will be setup soon! You can also take advantage of our Windows & ASP.NET Hosting support with Unlimited Domain, Unlimited Bandwidth, Unlimited Disk Space, etc.


May 22, 2015 07:59 by
Peter
Today, I am going to tell you about ASP.NET How to get all file names in a folder using C#/VB.NET. Fisrt, create the new ASP.NET project and then write the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
public partial class GetAllFileNames : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string str = string.Empty;
str = str + "<ul>";
DirectoryInfo d = new DirectoryInfo(@"D:\TextFiles");//Assuming Test is your Folder
FileInfo[] Files = d.GetFiles("*.*"); //Getting Text files
foreach (FileInfo file in Files)
{
str = str+"<li>" + file.Name;
}
str = str + "</li></ul>";
Response.Write(str);
}
}

VB:
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.IO
Partial Public Class GetAllFileNames
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim str As String = String.Empty
str = str & "<ul>"
Dim d As New DirectoryInfo("D:\TextFiles")
'Assuming Test is your Folder
Dim Files As FileInfo() = d.GetFiles("*.*")
'Getting Text files
For Each file As FileInfo In Files
str = str & "<li>" & file.Name
Next
str = str & "</li></ul>"
Response.Write(str)
End Sub
End Class
And here is the output from the above code:

Free ASP.NET 5 Hosting
Try our Free ASP.NET 5 Hosting today and your account will be setup soon! You can also take advantage of our Windows & ASP.NET Hosting support with Unlimited Domain, Unlimited Bandwidth, Unlimited Disk Space, etc.


May 18, 2015 07:11 by
Peter
In this short article, let me show you how to create two buttons "one for UP" and "one for DOWN" in the datagrid then you can easily move row up and down by using the following code.

Add code in Default.aspx page:
<asp:DataGrid ID="dgrdAdmin" runat="server" OnItemCommand="dgrdAdmin_ItemCommand" AllowSorting="true">
<Columns>
<asp:BoundColumn DataField="id" Visible="false"></asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:ImageButton ID="imgbtnUP" runat="server" CommandName="Up" />
<asp:ImageButton ID="imgbtnDown" runat="server" CommandName="Down" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
Now, write the following code:
private int GetMaxSortOrder()
{
int max = 0;
DataTable dt = new DataTable();
SqlConnection conn = new SqlConnection("Your_Connection_String");
SqlCommand cmd = new SqlCommand("SELECT MAX(SORTORDER) FROM Your_Admin_Table");
conn.Open();
SqlDataAdapter sqad = new SqlDataAdapter(cmd);
sqad.Fill(dt);
if (dt.Rows.Count > 0)
{
if (dt.Rows[0][0].ToString() != "")
max = Convert.ToInt32(dt.Rows[0][0]);
}
return max;
}
protected void dgrdAdmin_ItemCommand(object sender, DataGridCommandEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
if (e.CommandName.Equals("Up"))
{
int SortOrder = 0;
SqlConnection conn = new SqlConnection("Your_Connection_String");
if (e.Item.Cells[10].Text != "")
{
SortOrder = Convert.ToInt32(e.Item.Cells[10].Text);
if (SortOrder == 0)
{
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand("SELECT id FROM Your_ADMIN_Table");
conn.Open();
SqlDataAdapter sqad = new SqlDataAdapter(cmd);
sqad.Fill(dt);
if (dt.Rows.Count > 0)
{
int count = 0;
foreach (DataRow dr in dt.Rows)
{
count++;
SqlCommand cmdUp = new SqlCommand("UPDATE Your_ADMIN_Table SET
SortOrder='" + count + "' WHERE id='" + dr["id"].ToString() + "'");
cmdUp.ExecuteNonQuery();
}
}
// bind your grid
return;
}
}
if (SortOrder == GetMaxSortOrder() || SortOrder > GetMaxSortOrder())
return;
SqlCommand cmd2 = new SqlCommand("UPDATE Your_ADMIN_Table SET
SortOrder='" + SortOrder + "' WHERE SortOrder='" + (SortOrder + 1) + "'");
cmd2.ExecuteNonQuery();
SqlCommand cmd3 = new SqlCommand("UPDATE Your_ADMIN_Table SET
SortOrder='" + (SortOrder + 1) + "' WHERE id='" + e.Item.Cells[1].Text + "' AND
SortOrder='" + SortOrder + "'");
cmd3.ExecuteNonQuery();
dgrdAdmin.DataSource = // Bind data in datagrid
dgrdAdmin.DataBind();
}
if (e.CommandName.Equals("Down"))
{
SqlConnection conn = new SqlConnection("Your_Connection_String");
int SortOrder = 0;
if (e.Item.Cells[10].Text != "")
{
SortOrder = Convert.ToInt32(e.Item.Cells[10].Text);
if (SortOrder == 0)
{
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand("SELECT id FROM Your_ADMIN_Table");
conn.Open();
SqlDataAdapter sqad = new SqlDataAdapter(cmd);
if (dt.Rows.Count > 0)
{
int count = 0;
foreach (DataRow dr in dt.Rows)
{
count++;
SqlCommand cmdDown = new SqlCommand("UPDATE Your_ADMIN_Table SET
SortOrder='" + count + "' WHERE id='" + dr["id"].ToString() + "'");
cmdDown.ExecuteNonQuery();
}
}
// bind your grid
return;
}
}
if (SortOrder == 0)
return;
SqlCommand cmd1 = new SqlCommand("UPDATE Your_ADMIN_Table SET SortOrder=" + SortOrder + "' WHERE SortOrder='" + (SortOrder - 1) + "'");
cmd1.ExecuteNonQuery();
SqlCommand cmd2 = new SqlCommand("UPDATE Your_ADMIN_Table SET SortOrder='" + (SortOrder - 1) + "' WHERE id='" + e.Item.Cells[1].Text + "'
AND SortOrder='" + SortOrder + "'");
cmd2.ExecuteNonQuery();
dgrdAdmin.DataSource = // Bind data in datagrid
dgrdAdmin.DataBind();
}
}
}
Now you can easily move your datagrid row up and down with sorting.
Free ASP.NET 5 Hosting
Try our Free ASP.NET 5 Hosting today and your account will be setup soon! You can also take advantage of our Windows & ASP.NET Hosting support with Unlimited Domain, Unlimited Bandwidth, Unlimited Disk Space, etc.


May 11, 2015 08:12 by
Peter
In this tutorial, I will show you How to Open URL in New Window with Custom Height Width Example using AngularJS and ASP.NET 5. I using “$window.open” we will new popup browser window with custom size in AngularJS. Now, I will be able to explain how to open new browser window with custom height and width on button click using AngularJS.

Write the following code:
// Open New Child / Browser Window
$scope.openChildWindow = function () {
var left = screen.width / 2 - 200, top = screen.height / 2 – 250
$window.open('http://www.hostforlife.eu', '', "top=" + top + ",left=" + left + ",width=400,height=500")
}
This is the complete code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title> How to Open URL in New Window with Custom Height Width Example using AngularJS and ASP.NET?</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script>
<script type="text/javascript">
var myApp = angular.module('sampleapp', [])
myApp.controller("expressionController", function ($scope,$window) {
// Open New Child / Browser Window
$scope.openChildWindow = function () {
var left = screen.width / 2 - 200, top = screen.height / 2 – 250
$window.open('http://www.hostforlife.eu', '', "top=" + top + ",left=" + left +
,width=400,height=500")
}
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div data-ng-app="sampleapp" data-ng-controller="expressionController">
<input type="button" value="Open Popup Window" ng-click="openChildWindow()"/> <br /><br />
</div>
</form>
</body>
</html>
Free ASP.NET 5 Hosting
Try our Free ASP.NET 5 Hosting today and your account will be setup soon! You can also take advantage of our Windows & ASP.NET Hosting support with Unlimited Domain, Unlimited Bandwidth, Unlimited Disk Space, etc.


May 8, 2015 07:57 by
Peter
In this article, let me show you how to create a responsive page using BootStrap in ASP.NET. First of all, you must download BootStrap from bootstrap.com. Next step, Open your Visual Studio, add your downloaded file into your project then create the index.aspx page and call your necessary files with in the head tag from that downloaded folder.
Then, write the following code:

<head runat="server">
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<link href="css/bootstrap.min.css" rel="stylesheet" />
</head>
Consider <div class="row"></div> as a new line. Whatever you want to design in a row you should design with in a <div class="row">Your design</div>. And then <div class="col-lg-12"></div>
<div class="row">
<div class="col-lg-12">
Your Design
Create a Responsive Page Using BootStrap in ASP.NET
</div>
</div>
Full Code Sample
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="Responsive_Website.index" %>
<!DOCTYPE html>
<html
xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<link href="css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<form id="form1" runat="server">
<div class="container">
<div class="row">
<div class="col-lg-3"></div>
<div class="col-lg-6">
<form class="form-signin">
<h2 class="form-signin-heading">Please sign in</h2>
<label for="inputEmail" class="sr-only">Email address</label>
<input type="email" id="inputEmail" class="form-control" placeholder="Email
ddress" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" id="inputPassword" class="form-control"
laceholder="Password" required>
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me">
Remember me
</label>
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>
</div>
<div class="col-lg-3"></div>
</div>
</div>
</form>
</body>
</html>
And here is the output from the above code:

Output (on small screens)

Free ASP.NET Hosting
Try our Free ASP.NET Hosting today and your account will be setup soon! You can also take advantage of our Windows & ASP.NET Hosting support with Unlimited Domain, Unlimited Bandwidth, Unlimited Disk Space, etc.


May 4, 2015 08:41 by
Peter
In this post, I will tell you about using the MathCap for ASP.NET 5. MathCap is a plugin for ASP.NET application and its a 100% effective and simple to use. The more you see on a profound look. Here i imparted is the base form of Mathcap 1.0.0. More highlight are going ahead a newer versions. And now you must add mathcapp dll reference.


Remove the namespace on the webpage using MathCapcha;
Now write the following code
var bitmapImage = new Capcha();
var properties = new MathCapchaProperties();
Now, it is time to customise the properties.

Now get the response and point to image control, using below code:
var imgur = bitmapImage.CreateThumbnail(properties);
img.Src = imgur.bmpImageSource;
Response.Write(imgur.answer);
And here is the output:

Free ASP.NET Hosting
Try our Free ASP.NET Hosting today and your account will be setup soon! You can also take advantage of our Windows & ASP.NET Hosting support with Unlimited Domain, Unlimited Bandwidth, Unlimited Disk Space, etc.


April 17, 2015 07:11 by
Peter
In this post i will be able to show you how to discover loop in linked list with ASP.NET C#. We can notice the loop within the coupled list via Floyd’s Cycle-Finding formula, explained here. The method is pretty simple: We have a tendency to begin at the start of the linked list with 2 pointers. The primary pointer is incremented through every node of the list. The second pointer moves twice as quick, and skips each other node. If the coupled list contains a loop, these 2 pointers can eventually meet at the same node, so indicating that the linked list contains a loop.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Algo
{
public class Node
{
public Node Next { get; set; }
public int Value { get; set; }
public Node(int value)
{
this.Value = value;
}
}
public class LinkedList
{
private Node _head;
public LinkedList()
{
}
public void AppendLast(Node newNode)
{
if (_head == null)
{
_head = newNode;
}
else
{
Node current = _head;
while (current.Next != null)
{
current = current.Next;
}
current.Next = newNode;
}
}
public override string ToString()
{
Node current = _head;
StringBuilder builder = new StringBuilder();
while (current != null)
{
builder.Append(current.Value + "->");
current = current.Next;
}
return builder.ToString();
}
public bool IsCycle()
{
Node slow = _head;
Node fast = _head;
while (fast != null && fast.Next != null)
{
fast = fast.Next.Next;
slow = slow.Next;
if (slow == fast)
return true;
}
return false;
}
}
class Program
{
static void Main(string[] args)
{
LinkedList list = new LinkedList();
list.AppendLast(new Node(10));
list.AppendLast(new Node(20));
list.AppendLast(new Node(30));
Node cycle = new Node(40);
list.AppendLast(cycle);
list.AppendLast(new Node(60));
list.AppendLast(cycle);
if (list.IsCycle())
{
Console.WriteLine("Linked List is cyclic as it contains cycle or loop");
}
else
{
Console.WriteLine("LinkedList is not cyclic, no loop or cycle found");
}
}
}
}
Free ASP.NET Hosting
Try our Free ASP.NET Hosting today and your account will be setup soon! You can also take advantage of our Windows & ASP.NET Hosting support with Unlimited Domain, Unlimited Bandwidth, Unlimited Disk Space, etc. You will not be charged a cent for trying our service for the next 3 days. Once your trial period is complete, you decide whether you'd like to continue.


April 13, 2015 12:17 by
Peter
In this tutorial, I will show you how to Displaying SubTotal & Grand Total in ASP.NET 5. First, create new project. The records are isolated into Groups and after that SubTotal is calculated for every Group and then shown utilizing an element Row as a part of GridView. Now , I write the following code to create Products table:
CREATE TABLE [dbo].[Products](
[ProductID] [int] NULL,
[ProductName] [varchar](100) NULL,
[CategoryID] [int] NULL,
[UnitPrice] [decimal](18, 0) NULL,
[QuantityPerUnit] [varchar](100) NULL
) ON [PRIMARY]
GO
First create new web apps and open your GridViewSubTotalTotal.aspx and write the following code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title> Displaying SubTotal & Grand Total in ASP.NET 5</title>
</head>
<body>
<form id="form1" runat="server">
<h3 style="color:Green">Display SubTotal and Grand Total in ASP.Net GridView</h3>
<div>
<asp:GridView ID="gvData" runat="server" BackColor="White" BorderColor="#CC9966"
AutoGenerateColumns="false" BorderStyle="Solid" BorderWidth="1px" CellPadding="4"
Font-Names="Tahoma" Font-Size="Small" Width="475px" OnRowCreated="gvData_RowCreated"
nDataBound="gvData_OnDataBound">
<Columns>
<asp:BoundField DataField="ProductID" HeaderText="ProductID" />
<asp:BoundField DataField="CategoryID" HeaderText="Category ID" />
<asp:BoundField DataField="ProductName" HeaderText="ProductName" />
<asp:BoundField DataField="Price" HeaderText="Price" DataFormatString="{0:N2}"/>
</Columns>
<FooterStyle BackColor="Tan" />
<AlternatingRowStyle BackColor="#E6E6E1" />
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
</asp:GridView>
</div>
</form>
</body>
</html>
Next step, write the code below: GridViewSubTotalTotal.aspx.cs:
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Drawing;
public partial class GridViewSubTotalTotal : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGridData();
}
}
protected void BindGridData()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConString"].ConnectionString);
string sqlQuery = "SELECT ProductID,ProductName,CategoryID,(UnitPrice*QuantityPerUnit) AS Price FROM Products";
sqlQuery = sqlQuery + " WHERE CategoryID in(1,2,3) ORDER BY ProductID ASC";
SqlCommand cmd = new SqlCommand(sqlQuery, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
gvData.DataSource = ds;
gvData.DataBind();
}
int currentId = 0;
decimal subTotal = 0;
decimal total = 0;
int subTotalRowIndex = 0;
protected void gvData_RowCreated(object sender, GridViewRowEventArgs e)
{
subTotal = 0;
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataTable dt = (e.Row.DataItem as DataRowView).DataView.Table;
int ProductID = Convert.ToInt32(dt.Rows[e.Row.RowIndex]["ProductID"]);
total += Convert.ToDecimal(dt.Rows[e.Row.RowIndex]["Price"]);
if (ProductID != currentId)
{
if (e.Row.RowIndex > 0)
{
for (int i = subTotalRowIndex; i < e.Row.RowIndex; i++)
{
subTotal += Convert.ToDecimal(gvData.Rows[i].Cells[3].Text);
}
this.AddTotalRow("Sub Total", subTotal.ToString("N2"));
subTotalRowIndex = e.Row.RowIndex;
}
currentId = ProductID;
}
}
}
private void AddTotalRow(string labelText, string value)
{
GridViewRow row = new GridViewRow(0, 0, DataControlRowType.DataRow, DataControlRowState.Normal);
row.BackColor = ColorTranslator.FromHtml("#FFA500");
row.Cells.AddRange(new TableCell[4] {new TableCell { Text = labelText, HorizontalAlign = HorizontalAlign.Right},
new TableCell (),
new TableCell(), //Empty Cell,
new TableCell { Text = value, HorizontalAlign = HorizontalAlign.Right }
);
row.Cells[0].BorderColor = System.Drawing.Color.Orange;
row.Cells[1].BorderColor = System.Drawing.Color.Orange;
row.Cells[2].BorderColor = System.Drawing.Color.Orange;
row.Cells[3].BorderColor = System.Drawing.Color.Orange;
gvData.Controls[0].Controls.Add(row);
}
protected void gvData_OnDataBound(object sender, EventArgs e)
{
for (int i = subTotalRowIndex; i < gvData.Rows.Count; i++)
{
subTotal += Convert.ToDecimal(gvData.Rows[i].Cells[3].Text);
}
this.AddTotalRow("Sub Total", subTotal.ToString("N2"));
this.AddTotalRow("Total", total.ToString("N2"));
}
}
I hope this tutorial works for you!
Free ASP.NET 5 Hosting
Try our Free ASP.NET 5 Hosting today and your account will be setup soon! You can also take advantage of our Windows & ASP.NET Hosting support with Unlimited Domain, Unlimited Bandwidth, Unlimited Disk Space, etc. You will not be charged a cent for trying our service for the next 3 days. Once your trial period is complete, you decide whether you'd like to continue.
