如何计算累积频率 [英] how to calculate cummulative frequency

查看:318
本文介绍了如何计算累积频率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi如何在gridview中计算累积频率?使用gridview col1的列值cf 2 2 3 5 4 8 5 13像这样.用户将只输入第一个col值..如何使用gridview计算第二个列值.我的编码是

hi how to calculate cummulative frequency in gridview ? using column values of gridview col1 cf 2 2 3 5 4 8 5 13 like this. the user will enter only the first col values.. how to calculate second column values using gridview. my coding is

string  pr1 = gv.Rows[0].Cells[4].ToString();
    //int pr = System.Convert.ToInt32(pr1);
    int rw1;
    for (int ri =0; ri <= gv.Rows.Count - 2; ri++)
    {

        GridViewRow rw = gv.Rows[ri];
        GridViewRow prrw = gv.Rows[ri+1];
        //for (int i = 1; i < rw.Cells.Count; i++)
        //{
            prrw.Cells[5].Text = pr1;
            rw1 = System.Convert.ToInt32(rw.Cells[4].Text) + System.Convert.ToInt32(prrw.Cells[4].Text);
            pr1 = rw1.ToString ();
    }


但输出显示为


but the output was displaying

col1   cf
2
3   System.Web.UI.WebControls.DataControlFieldCell
4   5
6   7
8   10

推荐答案


假设您的两列都是数据绑定的.我有这样的aspx代码

Hi
Assuming you have both columns are databound. I have the aspx code like this

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

    DataSourceID="SqlDataSource1"

     OnDataBound="GridView1_OnDatabound">
    <Columns>
        <asp:BoundField DataField="col1" HeaderText="col1" SortExpression="col1" />
        <asp:BoundField DataField="cf" HeaderText="cf" SortExpression="cf" />
    </Columns>
</asp:GridView>



onDatabound事件我正在计算cf,并按如下所示进行填充.再次假设col1是第一列,而cf是第二列,否则您需要根据gridview更改索引位置



onDatabound event I am calculating the cf and populate as follows. Again assuming the col1 is the first column and cf is the second one, otherwise you need to change the index position as per your gridview

protected void GridView1_OnDatabound(object sender, EventArgs e)
{
    int cf =0;
    int currentValue = 0;
    foreach (GridViewRow row in GridView1.Rows)
    {
        currentValue = Convert.ToInt32(row.Cells[0].Text);
        cf += currentValue;
        row.Cells[1].Text = cf.ToString();
    }
}



让我知道是否可行!



Let me know if that works!


这篇关于如何计算累积频率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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