I wrote this code. It is not showing serial no according to my requirements. How to do it ?
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string Id = GridView1.DataKeys[e.Row.RowIndex].Value.ToString();
GridView gvResult = e.Row.FindControl("gvResult") as GridView;
//gvResult.DataSource = GetData(string.Format("select Convert ( Varchar (50) , Row_Number () Over (Order By sr.AdmissionNo ) ) as [Sr.No],ts.AdmissionNo,SubjectName,MaxMarks,Marks,Round((Marks) * 100/ (MaxMarks),1) as Percentage,CASE WHEN Round((Marks) * 100/ (MaxMarks),1) >= 80 THEN 'A+' WHEN Round((Marks) * 100/ (MaxMarks),1) >= 70 THEN 'A' WHEN Round((Marks) * 100/ (MaxMarks),1) >= 60 THEN 'B' WHEN Round((Marks) * 100/ (MaxMarks),1) >= 50 THEN 'C' WHEN Round((Marks) * 100/ (MaxMarks),1) >= 40 THEN 'D' WHEN Round((Marks) * 100/ (MaxMarks),1) >= 33 THEN 'E' ELSE 'FAIL' END AS Grade,CASE WHEN Round((Marks) * 100/ (MaxMarks),1) >= 80 THEN 'OutStanding' WHEN Round((Marks) * 100/ (MaxMarks),1) >= 70 THEN 'Excellent' WHEN Round((Marks) * 100/ (MaxMarks),1) >= 60 THEN 'Very Good' WHEN Round((Marks) * 100/ (MaxMarks),1) >= 50 THEN 'Good' WHEN Round((Marks) * 100/ (MaxMarks),1) >= 40 THEN 'Satisfactory' WHEN Round((Marks) * 100/ (MaxMarks),1) >= 33 THEN 'Work Hard' ELSE 'FAIL' END AS Remarks,dense_rank() over(partition BY (MaxMarks) order by (Marks) DESC) AS Position from tblSetMarks as ts inner join tblStdReg as sr on ts.AdmissionNo=sr.AdmissionNo inner join tblDefClass as dc on ts.ClassID=dc.ClassID inner join tblDefSection as ds on ts.SectionID=ds.SectionID inner join tblDefSubject as dsu on ts.SubjectID=dsu.SubjectID where sr.AdmissionNo='{0}' order by [Sr.No]", Id));
gvResult.DataSource = GetData(string.Format(@"DECLARE @AdmissionNo VARCHAR(10)
;WITH cteStudentMarksDetails
AS (
select Convert ( INT, Row_Number () OVER (ORDER BY sr.AdmissionNo ) ) AS [Sr.No]
,ts.AdmissionNo
,SubjectName
,MaxMarks
,Marks
,Round((Marks) * 100/ (MaxMarks),1) as SubjectPercentage
,DENSE_RANK() over(partition BY (SELECT MAX(Marks) FROM tblSetMarks TSS Where Tss.SubjectID = ts.SubjectID AND Tss.ClassID = ts.ClassID) order by ((Round((SELECT Marks FROM tblSetMarks TSS Where Tss.AdmissionNo = ts.AdmissionNo AND Tss.SubjectID = ts.SubjectID AND Tss.ClassID = ts.ClassID) * 100 / (SELECT MAX(Marks) FROM tblSetMarks TSS Where Tss.SubjectID = ts.SubjectID AND Tss.ClassID = ts.ClassID),1) )) DESC) AS SubjectPosition
,CASE WHEN Round((Marks) * 100/ (MaxMarks),1) >= 90 THEN 'A+'
WHEN Round((Marks) * 100/ (MaxMarks),1) >= 80 THEN 'A'
WHEN Round((Marks) * 100/ (MaxMarks),1) >= 70 THEN 'B'
WHEN Round((Marks) * 100/ (MaxMarks),1) >= 60 THEN 'C'
WHEN Round((Marks) * 100/ (MaxMarks),1) >= 50 THEN 'D'
WHEN Round((Marks) * 100/ (MaxMarks),1) >= 40 THEN 'E'
ELSE 'FAIL' END AS Grade,
CASE WHEN Round((Marks) * 100/ (MaxMarks),1) >= 90 THEN 'OutStanding'
WHEN Round((Marks) * 100/ (MaxMarks),1) >= 80 THEN 'Excellent'
WHEN Round((Marks) * 100/ (MaxMarks),1) >= 70 THEN 'Very Good'
WHEN Round((Marks) * 100/ (MaxMarks),1) >= 60 THEN 'Good'
WHEN Round((Marks) * 100/ (MaxMarks),1) >= 50 THEN 'Satisfactory'
WHEN Round((Marks) * 100/ (MaxMarks),1) >= 40 THEN 'Work Hard'
ELSE 'FAIL' END AS Remarks
,(Round((SELECT SUM(Marks) FROM tblSetMarks TSS WHERE Tss.AdmissionNo = ts.AdmissionNo) * 100/ (SELECT SUM(MaxMarks) FROM tblSetMarks TSS WHERE Tss.AdmissionNo = ts.AdmissionNo),1) ) TotalPercentage
,DENSE_RANK() OVER(ORDER BY ((ROUND((SELECT SUM(Marks) FROM tblSetMarks TSS WHERE Tss.AdmissionNo = ts.AdmissionNo) * 100 / (SELECT SUM(MaxMarks) FROM tblSetMarks TSS WHERE Tss.AdmissionNo = ts.AdmissionNo),1) )) DESC) AS ClassPosition
FROM tblSetMarks AS ts
INNER JOIN tblStdReg AS sr ON ts.AdmissionNo=sr.AdmissionNo
INNER JOIN tblDefClass AS dc ON ts.ClassID=dc.ClassID
INNER JOIN tblDefSection AS ds ON ts.SectionID=ds.SectionID
INNER JOIN tblDefSubject AS dsu ON ts.SubjectID=dsu.SubjectID
)
SELECT * FROM cteStudentMarksDetails WHERE AdmissionNo = '{0}' ORDER BY [Sr.No]", Id));
gvResult.DataBind();
}
}