如何在标签上的gridview页脚中显示我的一个列单元格值。 [英] How to display one of my column cell values in gridview footer on a label.

查看:67
本文介绍了如何在标签上的gridview页脚中显示我的一个列单元格值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我用来填充网格视图的查询:

  string  str = < span class =code-keyword> string  .Format( @ 选择m.pcode,m。 fyyear,m.date,m.salary,m.ta,m.contigency,m.nrc,m.institcharges,m.others,p.total FROM每月AS m内部联接项目p p.pcode = m.pcode其中m.pcode ='{0}',DropDownList1.SelectedItem.Value.ToString()); 



我想要的是来自总列显示在标签上的网格视图页脚中。

总列的值在每一行都是相同的,所以我们选择哪个单元格无关紧要我想实际隐藏此列以网格视图显示。我只需要从这一列中提取值。



我应该使用哪个事件?

解决方案

你应该这样试试



<前lang =cs> 受保护 void gvHardware_RowDataBound( object sender,GridViewRowEventArgs e)
{
int intFirstYearAmt;

if (e.Row.RowType == DataControlRowType.DataRow)
{

intFirstYearAmt = Convert.ToInt32(((DataRowView)e.Row.DataItem)[ ColumnName]。ToString( ));
// _intSumFisrtYear是全局变量,因此声明为全局变量。
_intSumFisrtYear + = intFirstYearAmt;

}
if (e.Row.RowType == DataControlRowType.Footer)
{

标签lbl2010 =(标签)e.Row.FindControl( lblFooterFirstYear);

lbl2010.Text = _intSumFisrtYear.ToString();

_intSumFisrtYear = 0 ;
}
}





我希望这会帮助你


你的语法错了



// total = Convert.ToInt32((DataRowView)e.Row.DataItem [total]。ToString());



这样写的



total = Convert.ToInt32(((DataRowView)e.Row.DataItem)[ total]。ToString());


不确定............

研究这个...

< asp:gridview id =GridView1onrowdatabound =RowDataBound_gv/> 



 protected void RowDataBound_gv(object sender,EventArgs e)
{
double total;
foreach(gvPoDetails.Rows中的GridViewRow gvr)
{
Label lblTot =(Label)gvr.Cells(9).Text;
total + = double.Parse(lblTot.Text);
}

标签lblTotFooter =(标签)GridView1.FindControl(label25);
lblTotFooter.Text = total.ToString();
}


This is the query I am using to populate my grid view:

string str = string.Format(@"select m.pcode, m.fyyear, m.date, m.salary, m.ta, m.contigency, m.nrc, m.institcharges, m.others, p.total FROM monthly AS m inner join project p on p.pcode=m.pcode where m.pcode = '{0}'", DropDownList1.SelectedItem.Value.ToString());


What I would like is that the value from total column is displayed in grid view footer on a label.
The value of total column is same along every row so it does not matter which ever cell we choose plus I would like to hide this column from actually being displayed in grid view. I only need to extract the value from this column.

Which event should I use?

解决方案

HI , u should try like that

protected void gvHardware_RowDataBound(object sender, GridViewRowEventArgs e)
  {
      int intFirstYearAmt;
      
      if (e.Row.RowType == DataControlRowType.DataRow)
      {

          intFirstYearAmt = Convert.ToInt32(((DataRowView)e.Row.DataItem)["ColumnName"].ToString());
// _intSumFisrtYear is global variable so declare as a global. 
          _intSumFisrtYear += intFirstYearAmt;

      }
      if (e.Row.RowType == DataControlRowType.Footer)
      {

          Label lbl2010 = (Label)e.Row.FindControl("lblFooterFirstYear");

          lbl2010.Text = _intSumFisrtYear.ToString();

          _intSumFisrtYear = 0;
      }
  }



I HOPE THIS WILL HELP U


your syntax is wrong

//total = Convert.ToInt32((DataRowView)e.Row.DataItem["total"].ToString());

Write like this

total = Convert.ToInt32(((DataRowView)e.Row.DataItem)["total"].ToString());


not sure............
study this...

<asp:gridview id="GridView1" onrowdatabound="RowDataBound_gv" /> 


protected void RowDataBound_gv(object sender, EventArgs e)
    {
        double total;
        foreach (GridViewRow gvr in gvPoDetails.Rows)
        {
            Label lblTot = (Label)gvr.Cells(9).Text;
            total+= double.Parse(lblTot.Text);
        }

        Label lblTotFooter = (Label)GridView1.FindControl("label25");
        lblTotFooter.Text=total.ToString();
    }


这篇关于如何在标签上的gridview页脚中显示我的一个列单元格值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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