ru ti

解决方案 »

  1.   


    此例合并第2.3列
    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    if(!IsPostBack)
    {
    DataTable table =tempTable();
    DataGrid1.DataSource =table;
    DataGrid1.DataBind(); }
    }
    DataTable tempTable()
    {
    DataTable table =new DataTable();
    table.Columns.Add(new DataColumn("ID",typeof(System.Int32)));
    table.Columns.Add(new DataColumn("FirstName",typeof(System.String)));
    table.Columns.Add(new DataColumn("LastName",typeof(System.String))); for(int i=0;i<5;i++)
    {
    DataRow row =table.NewRow();
    row["ID"] =i;
    row["FirstName"]=i.ToString();
    row["LastName"]=i.ToString();
    table.Rows.Add(row);
    }
    return table;
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.DataGrid1.PreRender += new System.EventHandler(this.DataGrid1_PreRender);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void DataGrid1_PreRender(object sender, System.EventArgs e)
    {
    for(int i=0;i<DataGrid1.Items.Count;i++)
    {
    TableCell cell1 =DataGrid1.Items[i].Cells[1];
    TableCell cell2 =DataGrid1.Items[i].Cells[2];
    cell1.Text +=cell2.Text;
    cell1.ColumnSpan =2;
    cell2.Visible =false; } }
      

  2.   

    合并列:参见下面合并第一列(此列内容我只取了第一列内容)
    private void DataGrid1_PreRender(object sender, System.EventArgs e)
    {
    //合并2.3行,同时合并第一列
    for(int i=0;i<DataGrid1.Items.Count;i++)
    {
    //合并2.3行
    TableCell cell1 =DataGrid1.Items[i].Cells[1];
    TableCell cell2 =DataGrid1.Items[i].Cells[2];
    cell1.Text +=cell2.Text;
    cell1.ColumnSpan =2;
    cell2.Visible =false;
    //合并第一列
    TableCell cell =DataGrid1.Items[i].Cells[0];
    cell.RowSpan =DataGrid1.Items.Count;
    if(i>0)
    cell.Visible=false; }
    }
      

  3.   

    http://singlepine.cnblogs.com/articles/282990.html