各位大神,求救。用GridView 实现。如何动态的添加 行的双击事件。和统计行
我想实现的功能是根据部门
动态的生成生成每个部门的销售报表 用GridView 实现。
现在问题是 如何动态的生成GridView 添加行的双击事件。
还有统计汇总数据
简易代码如下
ListDeptCategory = ViewState["ListDeptCategory"] as IList;
int iCount = ListDeptCategory.Count; //所有部门
for (int i = 1; i <= 1; i++)
{
CategoryInfo catItemInfo = ListDeptCategory[i - 1] as CategoryInfo;
GridView deptGridControl = CreateOneGrid(catItemInfo.CategoryCode, GridType.DeptGrid, true, true, dt);
deptGridControl.DataBind();
plDeptContainer.Controls.Add(deptGridControl);
}
/// <summary>
/// 创建一个GRID
/// </summary>
/// <param name="gridName">需要创建的GRID名称</param>
/// <param name="gridType">GRID类型【GridType】 是部门还是商品分类的</param>
/// <param name="isShowFooter">是否显示汇总</param>
/// <returns></returns>
private GridView CreateOneGrid(string gridName, GridType gridType, bool isShowFooter, bool isShowSaleMoney, DataTable dt)
{
GridView oneGridView = new GridView();
oneGridView.DataSource = dt;
oneGridView.HeaderStyle.Font.Bold = true;
oneGridView.AutoGenerateColumns = false;//设置自动产生列为false
oneGridView.ID = gridName + "view";
BoundField theCol = null;
theCol = new BoundField();
theCol.HeaderText = "商品分类";
theCol.Visible = true;
theCol.DataField = "CategoryName";
oneGridView.Columns.Add(theCol);
theCol = new BoundField();
theCol.HeaderText = "销售总额";
theCol.Visible = true;
theCol.DataField = "saleMoney";
oneGridView.Columns.Add(theCol);
oneGridView.DataBind();
return oneGridView;
}
public override void CreateView() {
base.CreateView();
this.gvwQuery.RowDblClick += new GridViewPlus.RowDblClickEventHandler(gvwQuery_RowDblClick);
}
void gvwQuery_RowDblClick(object sender, int RowIndex) {
JSHelper.Alert(MyHelper.ToString( this.gvwQuery.SelectedDataKey["ProductName1"]));
this.BindDetailView();
}