DataGrid 分页栏添加合计显示

项目中遇到在分页栏添加统计显示的需要,经过观察,可以在该栏动态添加表格来实现:

#region private void dgPjList_ItemCreated()

        
private void dgPjList_ItemCreated(object sender, DataGridItemEventArgs e)
        {
            
if (e.Item.ItemType == ListItemType.Pager && ViewState[c_DataSetName] != null)
            {
                
const String c_TOTAL = "  総計 {0}件";
                DataSet dstTotal 
= (DataSet) ViewState[c_DataSetName];
                String strTotal 
= String.Format(c_TOTAL, dstTotal.Tables[0].Rows.Count);
                Table tbl 
= new Table();
                
int intRows = 0;

                tbl.Rows.Add(
new TableRow());
                tbl.Style.Add(
"width""100%");
                TableRow trPager 
= tbl.Rows[0];
                trPager.Cells.Add(
new TableCell());
                trPager.Cells.Add(
new TableCell());
                trPager.Cells[
0].HorizontalAlign = HorizontalAlign.Left;
                trPager.Cells[
0].Wrap = false;
                trPager.Cells[
0].Text = strTotal;
                trPager.Cells[
1].HorizontalAlign = HorizontalAlign.Right;
                trPager.Cells[
1].Wrap = false;
                e.Item.Cells[
0].Wrap = false;
                intRows 
= e.Item.Cells[0].Controls.Count;
                e.Item.Cells[
0].Controls.Add(tbl);
                
for (int i = 0; i < intRows; i++)
                {
                    trPager.Cells[
1].Controls.Add(e.Item.Cells[0].Controls[0]);
                }

            }
        }

        
#endregion
posted @ 2006-01-06 14:14  铱星  阅读(624)  评论(0编辑  收藏  举报