span cells in grid over multiple positions

Thread is closed for posting
3 posts, 0 answers
  1. Telerik Admin
    Telerik Admin avatar
    1679 posts
    Member since:
    Oct 2004

    Posted 14 Feb 2007 Link to this post

    Requirements

    RadGrid for ASP .NET version

    RadControls for ASP .NET AJAX version

    4.5.x and later


    2008.1.415 and later

    .NET version

    2.0 and later

    Visual Studio version

    2005 and later

    Programming language

    C#

    Browser support

    all supported by RadGrid for ASP .NET


    all browsers supported by RadControls for ASP .NET AJAX


     
    PROJECT DESCRIPTION
    This project demostrates how to span any given cell over a number of rows/columns, with autogenerated columns in the control. This can be useful when you want to add additional information pertaining only to a small subset of the data in the control.
  2. Sean
    Sean avatar
    18 posts
    Member since:
    Oct 2008

    Posted 31 Oct 2008 Link to this post

    This solution doesn't work when the page is posted back. When it is posted back an additional column is added to the far right. To reproduce just add a button to the page and click it.  What is causing this?
  3. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 03 Nov 2008 Link to this post

    Hello Sean,

    To eliminate the issue, you can alter the code-behind to:

    .cs
    using System;  
    using System.Data;  
    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 Telerik.WebControls;  
     
    public partial class _Default : System.Web.UI.Page  
    {  
        protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)  
        {  
            DataTable table = new DataTable();  
            table.Columns.Add("Column1");  
            table.Columns.Add("Column2");  
            table.Columns.Add("Column3");  
     
            table.Rows.Add(new object[] { "Cell11", "Cell12", "Cell13" });  
            table.Rows.Add(new object[] { "Cell21", "Cell22", "Cell23" });  
            table.Rows.Add(new object[] { "Cell31", "Test", "Test" });  
            table.Rows.Add(new object[] { "Test", "Cell42", "Cell43" });  
            table.Rows.Add(new object[] { "Test", "Cell52", "Cell53" });  
     
            RadGrid1.DataSource = table;  
        }  
        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
        {  
             
        }  
        protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)  
        {  
                 
        }  
        protected void RadGrid1_PreRender(object sender, EventArgs e)  
        {  
            foreach (GridDataItem dataItem in RadGrid1.MasterTableView.Items)  
            {  
                if (dataItem["Column2"].Text == dataItem["Column3"].Text)  
                    {  
                        dataItem["Column2"].ColumnSpan = 2;                      
                        dataItem["Column3"].Visible = false;  
                    }  
     
                    int previousItemIndex = dataItem.ItemIndex - 1;  
                    if (previousItemIndex >= 0)  
                    {  
                        if (dataItem["Column1"].Text == dataItem.OwnerTableView.Items[previousItemIndex]["Column1"].Text)  
                        {  
                            dataItem.OwnerTableView.Items[previousItemIndex]["Column1"].RowSpan = 2;                          
                            dataItem["Column1"].Visible = false;  
                        }  
                    }  
            }  
        }  
    }  
     

    I hope this helps.

    Sincerely yours,
    Yavor
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top