TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Karthik K
1.3k
479
50.1k
Gridview Grouping/Subtotal ?
Mar 20 2019 8:12 PM
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 ,
Reply
Answers (
1
)
Need using textbox value ONLY not specific number in codes
How to apply server side rejex in mvc .net