解决方案 »
- 刚接触MV3,请问如何绑定下拉菜单,谢谢
- 关于水晶报表的一些问题?
- 我的SQL 2000数据库中有一个字段的数据类型是bit,那么我的asp.net程序中想插入一条数据的话,那个数据类型是什么样的,怎么转换
- 第一个项目碰到难题了!关于根据数据生成曲线的,望各位指点
- 100分求助,完成在+100:关于excel和word内容,导入到网页的
- CSV 文件导入 SQL SERVER
- 请教达人,请问在GridView中如何添加Button按钮?
- vssdata在.net在怎么用呀?
- GridView中的模板列里放一panel,panel里放一linkbutton,linkbutton的command不起作用
- ""和null是不是一个概念?
- asp.net mvc里验证信息控件ValidationMessage的问题
- 关于页面退出
web打印你可以参考http://www.cnblogs.com/panshenglu/archive/2009/09/21/1571258.html
//添加合计
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView myrows = (DataRowView)e.Row.DataItem;
count1 += Convert.ToDouble(myrows[5].ToString ());
}
if (e.Row.RowType == DataControlRowType.Footer)
{
TableCell c = e.Row.Cells[1];
c.Controls.Clear();
c.Font.Bold = true;
c.Text = "合计"; e.Row.Cells[1].HorizontalAlign = HorizontalAlign.Center;
e.Row.Cells[6].Text = count1.ToString();
e.Row.Cells[6].HorizontalAlign = HorizontalAlign.Center;
}
}
是要上边的这个效果吗?看代码:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="200" OnRowDataBound="GridView1_RowDataBound" ShowFooter="True">
<Columns>
<asp:TemplateField HeaderText="序号" >
<ItemTemplate ></ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="数值" DataField="jbnum" />
</Columns>
</asp:GridView>
后台: double sum = 0;
int counter = 0;
int inext = 2; protected void Page_Load(object sender, EventArgs e)
{ Database db = new Database();
string sql = "select jbnum from jbtab";
DataTable dt = new DataTable();
dt = db.GetDataTable(sql);
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{ if (e.Row.RowType == DataControlRowType.DataRow)
{
counter++;
e.Row.Cells[0].Text = counter.ToString();
DataRowView myrows = (DataRowView)e.Row.DataItem;
sum += Convert.ToDouble(myrows[0].ToString());
} if ((counter + 1) % 6 == 0 && counter != 0)
{
GridViewRow row = new GridViewRow(0, 0, DataControlRowType.DataRow, DataControlRowState.Normal);
TableCell cellword = new TableCell();
TableCell cellvalue = new TableCell();
cellword.Text = "统计";
cellword.ForeColor = System.Drawing.Color.Red;
cellvalue.Text = sum.ToString(); row.Cells.Add(cellword);
row.Cells.Add(cellvalue);
GridView1.Controls[0].Controls.AddAt(e.Row.RowIndex+inext , row);
sum = 0;
counter =0 ;
inext++;
}
if (e.Row.RowType == DataControlRowType.Footer)
{
TableCell c = e.Row.Cells[0];
c.Controls.Clear();
c.Font.Bold = true;
c.Text = "统计";
c.ForeColor = System.Drawing.Color.Red;
e.Row.Cells[1].HorizontalAlign = HorizontalAlign.Center;
e.Row.Cells[1].Text = sum.ToString();
e.Row.Cells[1].HorizontalAlign = HorizontalAlign.Center;
} }inext 注意这个变量哦
private DataTable MakeData(DataTable dt,int iSize,int iColumnID)
{
int itmp=dt.Rows.Count%iSize;
int iColumn;
if(itmp==0)
iColumn=dt.Rows.Count/iSize;
else
iColumn=dt.Rows.Count/iSize+1;
DataTable newdt=new DataTable();
for(int i=0;i<iColumn;i++)
{
DataColumn dc=new DataColumn(dt.Columns[iColumnID].ColumnName+i,dt.Columns[iColumnID].DataType);
newdt.Columns.Add(dc);
}
for(int i=0;i<iSize;i++)
{
DataRow dr=newdt.NewRow();
for(int j=0;j<iColumn;j++)
{
if((i+j*iSize)<dt.Rows.Count)dr[dt.Columns[iColumnID].ColumnName+j]=dt.Rows[i+j*iSize][iColumnID];
}
newdt.Rows.Add(dr);
}
return newdt;
}this.DataGrid1.DataSource=MakeData(dt,8,0);
this.DataGrid1.DataBind();绑定的时候数据有错,可能是重写table了,所以绑定字段有误,暂时还没有想到解决方法。
GridView1.DataSource = MakeData(dt, 15, 0);
GridView1.DataBind();
写错了。