GridView Footer行为null

时间:2014-07-10 06:05:29

标签: c# asp.net gridview footer

页脚设置为可见,我可以看到它正在创建。但是当总数(表总和)被传递给它时,会出现错误,指示GridView2.FooterRow为空... totTable是指携带总数的DataTable。

ASPX:

ShowHeader="true" ShowFooter="true" FooterStyle-CssClass="FooterStyle"

CS:

 DataRow dr = totTable.Rows[0];
 foreach (DataControlField col in GridView2.Columns)
                {
                    foreach (DataColumn dc in totTable.Columns)
                    {
                        int i = GridView2.Columns.IndexOf(col);
                        GridView2.FooterRow.Cells[i].Text = dr[i].ToString();

                    }
                }

这背后的根本原因是什么?

2 个答案:

答案 0 :(得分:0)

绑定gridview后使用以下代码:

    public void CountGrandTotal()
    {
        int sum = 0;
        for (int i = 0; i <grdproduct.Rows.Count ; i++)
        {
            Label lblprice = (Label)grdproduct.Rows[i].FindControl("Label5");

            sum += int.Parse(lblprice.Text);
        }
        Label lblgtotal = (Label)grdproduct.FooterRow.FindControl("Label7");
        lblgtotal.Text = sum.ToString();

答案 1 :(得分:0)

在GridView的OnLoad方法上添加页脚。


>>> client = pymongo.MongoClient("mongodb://BackendUser:Xunison_123@cluster0-osaot.mongodb.net/test?retryWrites=true&w=majority")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.6/site-packages/pymongo/mongo_client.py", line 248, in __init__
    res = uri_parser.parse_uri(entity, port)
  File "/usr/lib/python3.6/site-packages/pymongo/uri_parser.py", line 308, in parse_uri
    options = split_options(opts)
  File "/usr/lib/python3.6/site-packages/pymongo/uri_parser.py", line 211, in split_options
    return validate_options(options)
  File "/usr/lib/python3.6/site-packages/pymongo/uri_parser.py", line 153, in validate_options
    option, value = validate(option, value)
  File "/usr/lib/python3.6/site-packages/pymongo/common.py", line 306, in validate
    value = validator(option, value)
  File "/usr/lib/python3.6/site-packages/pymongo/common.py", line 53, in raise_config_error
    raise ConfigurationError("Unknown option %s" % (key,))
pymongo.errors.ConfigurationError: Unknown option retryWrites

>>> client = pymongo.MongoClient("mongodb://BackendUser:Xunison_123@cluster0-osaot.mongodb.net/test?w=majority")
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/pymongo/mongo_client.py", line 363, in __init__
    self._ensure_connected(True)
  File "/usr/lib/python3.6/site-packages/pymongo/mongo_client.py", line 924, in _ensure_connected
    self.__ensure_member()
  File "/usr/lib/python3.6/site-packages/pymongo/mongo_client.py", line 797, in __ensure_member
    member, nodes = self.__find_node()
  File "/usr/lib/python3.6/site-packages/pymongo/mongo_client.py", line 888, in __find_node
    raise AutoReconnect(', '.join(errors))
pymongo.errors.AutoReconnect: [Errno -5] No address associated with hostname

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.6/site-packages/pymongo/mongo_client.py", line 366, in __init__
    raise ConnectionFailure(str(e))
pymongo.errors.ConnectionFailure: [Errno -5] No address associated with hostname
>>>