我有一个动态创建的GridView,我使用sql代码WITH ROLLUP
来显示列的总数。但是可以在空白单元格中显示单词总数吗?
GridView的:
<asp:GridView runat="server"
id="gvResults"
CssClass="tblResults"
onrowcreated= "gvResults_RowCreated"
AllowSorting="true"
OnSortCommand="gvResults_Sort"
DataKeyField="ID"
AutoGenerateColumns="true"
Visible =" true">
<HeaderStyle CssClass="tblResultsHeader" />
<AlternatingRowStyle BackColor="#EEEEEE" />
</asp:GridView>
显示GridView的SQL代码:
select
c.Name,
COUNT(distinct jn.ID) as Jobs,
sum(case when (select count(jbs.status) from jobstat jbs where jbs.jobid=jn.id and jbs.Status=''DEL'')>0 then 1 else 0 end) as EPOD,
sum(case when (select count(jbs.status) from jobstat jbs where jbs.jobid=jn.id and jbs.Status=''POD'')>0 then 1 else 0 end) as POD,
SUM((select COUNT(ID) from job_debriefs WHERE JobID = jn.ID)) as Debriefs,
FROM customer c
LEFT JOIN job_new jn ON jn.JobOwnerID = c.ID
LEFT JOIN manifestdetails md ON md.JobID = jn.ID and md.ColDelReturn = ''C''
LEFT JOIN manifest man ON md.ManifestID = man.ID
WHERE jn.IsActive = 1 AND c.Company_ID = 12
GROUP BY c.Name WITH ROLLUP
答案 0 :(得分:2)
您可以使用GROUPING
SQL函数来确定c.Name
是否卷起特定行:
select
ifnull(c.Name,'TOTAL') as Name,
COUNT(distinct jn.ID) as Jobs,
sum(case when (select count(jbs.status) from jobstat jbs where jbs.jobid=jn.id and jbs.Status=''DEL'')>0 then 1 else 0 end) as EPOD,
sum(case when (select count(jbs.status) from jobstat jbs where jbs.jobid=jn.id and jbs.Status=''POD'')>0 then 1 else 0 end) as POD,
SUM((select COUNT(ID) from job_debriefs WHERE JobID = jn.ID)) as Debriefs,
FROM customer c
LEFT JOIN job_new jn ON jn.JobOwnerID = c.ID
LEFT JOIN manifestdetails md ON md.JobID = jn.ID and md.ColDelReturn = ''C''
LEFT JOIN manifest man ON md.ManifestID = man.ID
WHERE jn.IsActive = 1 AND c.Company_ID = 12
GROUP BY c.Name WITH ROLLUP
但是,请注意,如果原始c.Name
列中允许NULL值,则此值也将转换为单词“TOTAL”。据我所知,在MySQL中没有解决方法(当然除了消除NULL值)。
答案 1 :(得分:0)
您可以参考to this link。它可能对你有所帮助。
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label Salary = (Label)e.Row.FindControl("lblSalary");
m = m + int.Parse(Salary.Text);
//Table tb = new Table();
}
if (e.Row.RowType == DataControlRowType.Footer)
{
Label lblTotalPrice = (Label)e.Row.FindControl("Salary");
lblTotalPrice.Text = m.ToString();
}
}