What you've given us as you're desired output is faulty.
The line
CLASS8 A01 Adi 2017 03/15/2017 Checkbox 2
says that there were 2 occurrences of A01/Adi having attended. But there was only one, the other was roll A02.
Also the batch_date columns don't match - your GridView has a single row for two different batch_dates.
So I'm going to assume you want to group results by role and batch_date, andmodify your data slightly to show how to show to get the data you're looking for in a single query, as Graeme suggested above.
Let's assume you have this table:-
USE [Penvro]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Attendance](
[id] [int] IDENTITY(1,1) NOT NULL,
[class] [int] NOT NULL,
[roll] [varchar](50) NOT NULL,
[name] [varchar](50) NOT NULL,
[batch_date] [datetime] NOT NULL,
[present] [char](1) NOT NULL,
CONSTRAINT [PK_Attendance] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
and you're populating it with this data:-
INSERT INTO Attendance (class, roll, name, batch_date, present) VALUES
(8, 'A01', 'Adi', '15-Mar-2017 11:30:46', 'P'),
(8, 'A01', 'Adi', '15-Mar-2017 11:30:46', 'P'),
(8, 'A03', 'Ram', '15-Mar-2017 11:30:46', 'A')
Then this query will return the results you need
SELECT class, roll, name, batch_date, CASE WHEN present='P' THEN 1 ELSE 0 END AS present_absent, count(*) AS total
FROM Attendance a
GROUP BY class, roll, name, batch_date, a.present
class roll name batch_date present_absent total
------- ----- ------ ----------------------- -------------- ------
8 A01 Adi 2017-03-15 00:00:00.000 1 2
8 A03 Ram 2017-03-15 00:00:00.000 0 1