Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
.NET
.NET Core
.NET MAUI
.NET Standard
Active Directory
ADO.NET
Agile Development
AI
AJAX
AlbertAGPT
Alchemy
Alexa Skills
Algorand
Algorithms in C#
Android
Angular
ArcObject
ASP.NET
ASP.NET Core
Augmented Reality
Avalanche
AWS
Azure
Backbonejs
Big Data
BizTalk Server
Blazor
Blockchain
Bootstrap
Bot Framework
Business
Business Intelligence(BI)
C#
C# Corner
C# Strings
C, C++, MFC
Career Advice
Careers and Jobs
Chapters
ChatGPT
Cloud
Coding Best Practices
Cognitive Services
COM Interop
Compact Framework
Copilot
Cortana Development
Cosmos DB
Cryptocurrency
Cryptography
Crystal Reports
CSS
Current Affairs
Custom Controls
Cyber Security
Data Mining
Data Science
Databases & DBA
Databricks
Design Patterns & Practices
DevExpress
DevOps
DirectX
Dynamics CRM
Enterprise Development
Entity Framework
Error Zone
Exception Handling
F#
Files, Directory, IO
Flutter
Games Programming
GDI+
General
Generative AI
GO
Google Cloud
Google Development
Graphics Design
Graphite Studio
Hardware
Hiring and Recruitment
HoloLens
How do I
HTML 5
Infragistics
Internet & Web
Internet of Things
Ionic
Java
Java and .NET
JavaScript
JQuery
JSON
JSP
Knockout
Kotlin
Langchain
Leadership
Learn .NET
Learn iOS Programming
LINQ
Machine Learning
Metaverse
Microsoft 365
Microsoft Fabric
Microsoft Office
Microsoft Phone
Microsoft Teams
Mobile Development
MongoDB
MuleSoft
MySQL
NEAR
NetBeans
Networking
NFT
NoCode LowCode
Node.js
Office Development
OOP/OOD
Open Source
Operating Systems
Oracle
Outsourcing
Philosophy
PHP
Polygon
PostgreSQL
Power Apps
Power Automate
Power BI
Power Pages
Printing in C#
Products
Progress
Progressive Web Apps
Project Management
Public Speaking
Python
Q#
QlikView
Quantum Computing
R
React
React Native
Reports using C#
Robotics & Hardware
RPA
Ruby on Rails
RUST
Salesforce
Security
Servers
ServiceNow
SharePoint
Sharp Economy
SignalR
Smart Devices
Snowflake
Software Architecture/Engineering
Software Testing
Solana
Solidity
Sports
SQL
SQL Server
Startups
Stratis Blockchain
Swift
SyncFusion
Threading
Tools
TypeScript
Unity
UWP
Visual Basic .NET
Visual Studio
Vue.js
WCF
Wearables
Web API
Web Design
Web Development
Web3
Windows
Windows Controls
Windows Forms
Windows PowerShell
Windows Services
Workflow Foundation
WPF
Xamarin
XAML
XML
XNA
XSharp
Register
Login
1
Answer
Gridview Grouping/Subtotal ?
Karthik K
5y
1.1k
1
Reply
Hi Friends ,
I have done Gridview grouping , In that i want to do subtotal as well as Grandtotal of it .I coulud share the code .if you suggest me with code .
Design :
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
>
</
title
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
div
align
=
"center"
>
<
table
style
=
"border:solid 15px Grey; width: 80%; vertical-align: central;"
>
<
tr
>
<
td
style
=
"padding-left: 20px; padding-top: 20px; padding-bottom: 20px; background-color: skyblue; font-family: 'Times New Roman'; font-size: 20pt; color: red;"
>
Showing Grouping Of Data In a ASP.NET Grid View - Cloud Live
</
td
>
</
tr
>
<
tr
>
<
td
style
=
"text-align: left;"
>
<
asp:GridView
ID
=
"GridView1"
runat
=
"server"
CellPadding
=
"4"
ForeColor
=
"#333333"
GridLines
=
"Both"
Width
=
"90%"
>
<
AlternatingRowStyle
BackColor
=
"White"
ForeColor
=
"#284775"
/>
<
EditRowStyle
BackColor
=
"#999999"
/>
<
FooterStyle
BackColor
=
"#5D7B9D"
Font-Bold
=
"True"
ForeColor
=
"White"
/>
<
HeaderStyle
BackColor
=
"#5D7B9D"
Font-Bold
=
"True"
ForeColor
=
"White"
/>
<
PagerStyle
BackColor
=
"#284775"
ForeColor
=
"White"
HorizontalAlign
=
"Center"
/>
<
RowStyle
BackColor
=
"#F7F6F3"
ForeColor
=
"#333333"
/>
<
SelectedRowStyle
BackColor
=
"#E2DED6"
Font-Bold
=
"True"
ForeColor
=
"#333333"
/>
<
SortedAscendingCellStyle
BackColor
=
"#E9E7E2"
/>
<
SortedAscendingHeaderStyle
BackColor
=
"#506C8C"
/>
<
SortedDescendingCellStyle
BackColor
=
"#FFFDF8"
/>
<
SortedDescendingHeaderStyle
BackColor
=
"#6F8DAE"
/>
</
asp:GridView
>
</
td
>
</
tr
>
</
table
>
</
div
>
</
form
>
</
body
>
</
html
>
backend :
private
void
BindGrid()
{
MySqlConnection Cn =
new
MySqlConnection(Constring);
ds =
new
DataSet();
MySqlCommand cmd =
new
MySqlCommand(
"SELECT concat(DATE_FORMAT(a.transtime,'%h:%00 %p'),'-',DATE_FORMAT(a.transtime,'%h:59 %p')) as Hour,B.BarCode,Sum(b.qty) as Qty, B.InventoryDesc, Sum(b.PSDiscAmount+b.ManualDisc+b.MemberDisc+b.TotalDisc) as Disamt, Sum(B.TaxableAmount+B.TaxAmount1+B.TaxAmount2+B.TaxAmount3+B.TaxAmount4+B.TaxAmount5+B.TaxAmount6) As Amount FROM rasa1.Trans A JOIN rasa1.TransDetail B on A.Transid=B.Transid Left Join rasa1.Customers C On a.CustomerNumber=C.CustomerNumber Where (A.BusinessDate Between '2019-03-20' And '2019-03-20') And B.ItemStatus<>1 Group by Hour,Barcode,CategoryNumber ORDER BY HOUR(a.TransTime)"
, Cn);
da =
new
MySqlDataAdapter(cmd);
da.Fill(ds);
Cn.Open();
cmd.ExecuteNonQuery();
Cn.Close();
if
(ds.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
// First parameter is Row Collection
// Second is Start Column
// Third is total number of Columns to make group of Data.
ShowingGroupingDataInGridView(GridView1.Rows, 0, 2);
}
}
Groupby Function :
void
ShowingGroupingDataInGridView(GridViewRowCollection gridViewRows,
int
startIndex,
int
totalColumns)
{
if
(totalColumns == 0)
return
;
int
i, count = 1;
ArrayList lst =
new
ArrayList();
lst.Add(gridViewRows[0]);
var ctrl = gridViewRows[0].Cells[startIndex];
for
(i = 1; i < gridViewRows.Count; i++)
{
TableCell nextTbCell = gridViewRows[i].Cells[startIndex];
if
(ctrl.Text == nextTbCell.Text)
{
count++;
nextTbCell.Visible =
false
;
lst.Add(gridViewRows[i]);
}
else
{
if
(count > 1)
{
ctrl.RowSpan = count;
ShowingGroupingDataInGridView(
new
GridViewRowCollection(lst), startIndex + 1, totalColumns - 1);
}
count = 1;
lst.Clear();
ctrl = gridViewRows[i].Cells[startIndex];
lst.Add(gridViewRows[i]);
}
}
if
(count > 1)
{
ctrl.RowSpan = count;
ShowingGroupingDataInGridView(
new
GridViewRowCollection(lst), startIndex + 1, totalColumns - 1);
}
count = 1;
lst.Clear();
}
Thanking You ,
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
Need using textbox value ONLY not specific number in codes
How to apply server side rejex in mvc .net