一个GridView中显示脚注中为每一列 [英] Show total of every column in footer within a gridview

查看:134
本文介绍了一个GridView中显示脚注中为每一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我想告诉每列总每列7至18有了这个code它给我的总的所有列并显示在页脚的每一个细胞。我想显示在等效页脚单元格每列总。我使用ASP:绑定列在ASP

例如:COLUMN1总和= 2,列2和= 3,栏3和= 4,本code给我相同的总2 + 3 + 4 = 9到footer.I的所有单元格想要展示在fo​​oter.cell [1] = 2,footer.cell [2] = 3,footer.cell [4] = 4(编程)。总的每个列,而不是全总各列。结果
有什么建议?

 私人INT TotalStats =(INT)0;
 保护无效GridViewHomeTeamStats_RowDataBound(对象发件人,GridViewRowEventArgs E)
    {
        的for(int i = 7; I< = 18;我++){
        //检查行类型
        如果(e.Row.RowType == DataControlRowType.DataRow)
            //如果行类型是DataRow的,加...
        {
            TotalStats + = Convert.ToInt32(e.Row.Cells [I]。文本);
        }
        否则,如果(e.Row.RowType == DataControlRowType.Footer)
            //如果行类型是页脚,显示计算总价值
            e.Row.Cells [I]。文本=的String.Format({0:0} ##,TotalStats);
            }
    }

感谢you.Can你帮我也与这三根柱子在这些列中的值,如:?3/4,5/6 etc.I想在相当于页脚单元格显示此列的总和除以。例如,如果一个列有两行具有值1/2,2/4我想在页脚单元格显示1 + 2/2 + 4 = 0.5 = 50%。
 这是在asp code,它是从同一GridViewHomeTeamStats:

 < ASP:GridView控件ID =GridViewHomeTeamStats=服务器的AutoGenerateColumns =FALSE的DataSourceID =SqlDataSourceHomeTeamShowFooter =真OnRowDataBound =GridViewHomeTeamStats_RowDataBound>
    <柱体和GT;
        < ASP:的TemplateField的HeaderText =FTSORTEX pression =FREE_THROW_MADE>
            <&ItemTemplate中GT;
                < ASP:标签ID =Label1的=服务器文本='<%#的eval(FREE_THROW_MADE)+/+的eval(FREE_THROW_ATTEMPT)%>'>< / ASP:标签>< / ItemTemplate中>
        < / ASP:的TemplateField>
        < ASP:的TemplateField的HeaderText =2PSORTEX pression =2POINTS_MADE>
            <&ItemTemplate中GT;
                < ASP:标签ID =Label2的=服务器文本='<%#的eval(2POINTS_MADE)+/+的eval(2POINTS_ATTEMPT)%>'>< / ASP:标签>
            < / ItemTemplate中>
        < / ASP:的TemplateField>
        < ASP:的TemplateField的HeaderText =3PSORTEX pression =3POINT_MADE>
            <&ItemTemplate中GT;
                < ASP:标签ID =LABEL3=服务器文本='<%#的eval(3POINT_MADE)+/+的eval(3POINT_ATTEMPT)%>'>< / ASP:标签>
            < / ItemTemplate中>
        < / ASP:的TemplateField>


解决方案

试试这个(可能我宁愿使用十进制):

  INT [] TotalStats =新INT [12] {0,0,0,0,0,0,0,0,0,0,0,0};保护无效GridViewHomeTeamStats_RowDataBound(对象发件人,GridViewRowEventArgs E)
{
    的for(int i = 7; I< = 18;我++)
    {
        //检查行类型
        如果(e.Row.RowType == DataControlRowType.DataRow)
        //如果行类型是DataRow的,加...
        {
            TotalStats [I-7] + = Convert.ToInt32(e.Row.Cells [I]。文本);
        }
        否则,如果(e.Row.RowType == DataControlRowType.Footer)
            //如果行类型是页脚,显示计算总价值
            e.Row.Cells [I]。文本=的String.Format({0:0} ##,TotalStats [I-7]);
    }
}

Hello I want to show each column total for every column 7 to 18. With this code it gives me the total of all the columns and shows it in every cell of the footer. I want to show each column total in the equivalent footer cell. I am using asp:BoundFields in asp.

example: column1 sum =2 ,column2 sum =3, column3 sum=4, with this code gives me the same total 2+3+4=9 to all the cells of the footer.I want to show in the footer.cell[1] =2,footer.cell[2] =3,footer.cell[4] =4 (programmatically). The total for each column and not the full total of all columns.
Any suggestions?

private int TotalStats = (int)0;
 protected void GridViewHomeTeamStats_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        for (int i = 7; i <= 18; i++){
        // check row type
        if (e.Row.RowType == DataControlRowType.DataRow)
            // if row type is DataRow, add ...                
        {
            TotalStats += Convert.ToInt32(e.Row.Cells[i].Text);
        }
        else if (e.Row.RowType == DataControlRowType.Footer)
            // If row type is footer, show calculated total value
            e.Row.Cells[i].Text = String.Format("{0:0.##}", TotalStats);
            }
    }

Thank you.Can you help me also with these three columns?In these columns the values are like: 3/4 ,5/6 etc.I want to show in the equivalent footer cell the sum and divide of this columns. Example if a column has 2 rows with values 1/2 , 2/4 I want to show 1+2/2+4=0.5=50% in the footer cell . this is the asp code that is from the same GridViewHomeTeamStats :

 <asp:GridView ID="GridViewHomeTeamStats" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSourceHomeTeam" ShowFooter="True" OnRowDataBound="GridViewHomeTeamStats_RowDataBound">
    <Columns>            
        <asp:TemplateField HeaderText="FT" SortExpression="FREE_THROW_MADE">
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Eval("FREE_THROW_MADE") + "/" + Eval("FREE_THROW_ATTEMPT") %>'></asp:Label></ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="2P" SortExpression="2POINTS_MADE">
            <ItemTemplate>
                <asp:Label ID="Label2" runat="server" Text='<%# Eval("2POINTS_MADE") + "/" + Eval("2POINTS_ATTEMPT") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="3P" SortExpression="3POINT_MADE">
            <ItemTemplate>
                <asp:Label ID="Label3" runat="server" Text='<%# Eval("3POINT_MADE") + "/" + Eval("3POINT_ATTEMPT") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>

解决方案

Try this (probably I would rather use decimal):

int[] TotalStats = new int[12] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

protected void GridViewHomeTeamStats_RowDataBound(object sender, GridViewRowEventArgs e)
{
    for (int i = 7; i <= 18; i++)
    {
        // check row type
        if (e.Row.RowType == DataControlRowType.DataRow)
        // if row type is DataRow, add ...                
        {
            TotalStats[i-7] += Convert.ToInt32(e.Row.Cells[i].Text);
        }
        else if (e.Row.RowType == DataControlRowType.Footer)
            // If row type is footer, show calculated total value
            e.Row.Cells[i].Text = String.Format("{0:0.##}", TotalStats[i-7]);
    }
}

这篇关于一个GridView中显示脚注中为每一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆