如图:
还真没有做过,哪位知道的朋友也帮忙一下。期待中。
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using ExtendGridView;
public partial class HT_16 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
bind();
}
}
public void bind()//绑定
{
GridViewExpend1.DataSource = this.CreateData();
GridViewExpend1.DataKeyNames = new string[] { "标识" };//主键
GridViewExpend1.DataBind();
}
public DataTable CreateStructure()
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("标识", typeof(int)));
dt.Columns.Add(new DataColumn("日期", typeof(DateTime)));
dt.Columns.Add(new DataColumn("批号", typeof(string)));
dt.Columns.Add(new DataColumn("HT-10", typeof(string)));
dt.Columns.Add(new DataColumn("盐酸", typeof(string)));
dt.Columns.Add(new DataColumn("亚硝酸钠", typeof(string)));
dt.Columns.Add(new DataColumn("HT-15", typeof(string)));
dt.Columns.Add(new DataColumn("数量", typeof(string)));
dt.Columns.Add(new DataColumn("含量", typeof(string)));
dt.Columns.Add(new DataColumn("HT-11", typeof(string)));
dt.Columns.Add(new DataColumn("HT-12", typeof(string)));
dt.Columns.Add(new DataColumn("[盐酸]", typeof(string)));
dt.Columns.Add(new DataColumn("[亚硫酸钠]", typeof(string)));
dt.Columns.Add(new DataColumn("HT-13", typeof(string)));
dt.Columns.Add(new DataColumn("液碱", typeof(string)));
dt.Columns.Add(new DataColumn("粗品数量", typeof(string)));
dt.Columns.Add(new DataColumn("粗品含量", typeof(string)));
dt.Columns.Add(new DataColumn("精品数量", typeof(string)));
dt.Columns.Add(new DataColumn("精品含量", typeof(string)));
return dt;
}
public DataSet CreateData()
{
DataSet ds = new DataSet();
DataTable dt = this.CreateStructure();
SqlCommand cmd = data.BuildSqlCommand("SELECT * FROM [Product_Ht16] Order by id Desc");
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
DataRow drNew = dt.NewRow();
drNew["标识"] = dr["id"].ToString();
drNew["日期"] = dr["ht1"].ToString();
drNew["批号"] = dr["ht2"].ToString().Trim();
drNew["HT-10"] = dr["ht3"].ToString().Trim();
drNew["盐酸"] = dr["ht4"].ToString().Trim();
drNew["亚硝酸钠"] = dr["ht5"].ToString().Trim();
drNew["HT-15"] = dr["ht6"].ToString().Trim();
drNew["数量"] = dr["ht7"].ToString().Trim();
drNew["含量"] = dr["ht8"].ToString().Trim();
drNew["HT-11"] = dr["ht9"].ToString().Trim();
drNew["HT-12"] = dr["ht10"].ToString().Trim();
drNew["[盐酸]"] = dr["ht11"].ToString().Trim();
drNew["[亚硫酸钠]"] = dr["ht12"].ToString().Trim();
drNew["HT-13"] = dr["ht13"].ToString().Trim();
drNew["液碱"] = dr["ht14"].ToString().Trim();
drNew["粗品数量"] = dr["ht15"].ToString().Trim();
drNew["粗品含量"] = dr["ht16"].ToString().Trim();
drNew["精品数量"] = dr["ht17"].ToString().Trim();
drNew["精品含量"] = dr["ht18"].ToString().Trim();
dt.Rows.Add(drNew);
}
ds.Tables.Add(dt);
return ds;
}
/// <summary>
/// 具体重写方法, 此方法比较灵活, 可以任意设置您需要创建的格式, 比如更复杂的表格
/// 另外, 可以直接从第二个参数中取得控件对象引用
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridViewExpend1_RebuildHeader(object sender, EventArgs e)
{
//取得参数e中包含的对象的引用
GridViewExpendHeader currentGVE = ((RebuildHeaderEventArgs)e).GridViewObject; //到操作当前GridView的对象引用
GridViewRow currentHeaderRow = ((RebuildHeaderEventArgs)e).HeaderRowObject; ////到操作当前GridView's HeaderRow的对象引用
//创建一个行并设置与GridViewExtend当前的头类型风格一致
GridViewRow willAddHeaderRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
willAddHeaderRow.Font.Bold = true;
willAddHeaderRow.BackColor = Color.FromName("#003399");
willAddHeaderRow.ForeColor = Color.FromName("#CCCCFF");
//在当前HeaderRow上面再增加一行
TableCell cell = new TableCell();
cell.Text = "标识";
cell.ColumnSpan = 4;
cell.HorizontalAlign = HorizontalAlign.Center;
willAddHeaderRow.Cells.Add(cell);
cell = new TableCell();
cell.Text = "第一步";
cell.ColumnSpan = 6; //跨6单元格
cell.HorizontalAlign = HorizontalAlign.Center;
willAddHeaderRow.Cells.Add(cell);
cell = new TableCell();
cell.Text = "第二步";
cell.ColumnSpan = 10; //跨10单元格
cell.HorizontalAlign = HorizontalAlign.Center;
willAddHeaderRow.Cells.Add(cell);
currentGVE.Controls[0].Controls.AddAt(0, willAddHeaderRow);
}
protected void FormView1_ItemInserted(object sender, FormViewInsertedEventArgs e)
{
bind();
}
}
[/CODE]
[此贴子已经被作者于2007-7-24 14:37:11编辑过]