Contact Sales: +1-888-365-2779
Community & Support
Skip Navigation LinksHome / Community & Support / Code Library / ASP.NET and ASP.NET AJAX > Grid > span cells in grid over multiple positions

Not answered span cells in grid over multiple positions

Feed from this thread
  • Posted on Feb 14, 2007 (permalink)

    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.

  • Sean avatar

    Posted on Oct 31, 2008 (permalink)

    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?

  • Yavor Yavor admin's avatar

    Posted on Nov 3, 2008 (permalink)

    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

Skip Navigation LinksHome / Community & Support / Code Library / ASP.NET and ASP.NET AJAX > Grid > span cells in grid over multiple positions