This is a migrated thread and some comments may be shown as answers.

Problems with merge row in Radgrid

9 Answers 364 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Trung Nguyen
Top achievements
Rank 1
Trung Nguyen asked on 12 Jul 2009, 02:10 AM
hi
i have code to merge row in radgird :

for (int i = RadGrid1.Items.Count - 2 ; i > 0; i--)  
            {  
                if (RadGrid1.Items[i][RadGrid1.Columns[0]].Text == RadGrid1.Items[i-1][RadGrid1.Columns[0]].Text)  
                {  
                    RadGrid1.Items[i-1][RadGrid1.Columns[0]].RowSpan = RadGrid1.Items[i][RadGrid1.Columns[0]].RowSpan < 2 ? 2 : RadGrid1.Items[i][RadGrid1.Columns[0]].RowSpan + 1;  
                    RadGrid1.Items[i][RadGrid1.Columns[0]].Visible = false;  
                }  
            }  

result:
<img src="http://img403.imageshack.us/img403/8326/65829250.jpg/>
http://img403.imageshack.us/img403/8326/65829250.jpg
cell mergered but lost border...how to draw border cell? help me plz


9 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 13 Jul 2009, 07:33 AM
Hello Trung,

Try adding the highlighted line of code given below and see if the cell borders display:
protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        for (int i = RadGrid1.Items.Count - 2; i > 0; i--) 
        { 
            if (RadGrid1.Items[i][RadGrid1.Columns[0]].Text == RadGrid1.Items[i - 1][RadGrid1.Columns[0]].Text) 
            { 
                RadGrid1.Items[i - 1][RadGrid1.Columns[0]].RowSpan = RadGrid1.Items[i][RadGrid1.Columns[0]].RowSpan < 2 ? 2 : RadGrid1.Items[i][RadGrid1.Columns[0]].RowSpan + 1; 
                RadGrid1.Items[i][RadGrid1.Columns[0]].Visible = false
                RadGrid1.Items[i][RadGrid1.Columns[0]].Text = "&nbsp"
            } 
        } 
    } 

Thanks
Princy.
0
Trung Nguyen
Top achievements
Rank 1
answered on 13 Jul 2009, 09:36 AM
thanks Princy
I tried but not working, help me...


0
Andy Spears
Top achievements
Rank 1
answered on 31 Jul 2009, 02:24 PM
I ran into the same problem, and this was the only way I was able to get borders to show.  My implementation of setting the RowSpan property is slightly different, but you should be able to get the gist of what needs to be done:

private string _previousHazerdousMaterial = ""
        private TableCell _hazMatTableCell = null
        protected void chemicalHazardsRadGrid_ItemDataBound( object sender, GridItemEventArgs e ) 
        { 
            switch ( e.Item.ItemType ) 
            { 
                case GridItemType.Item: 
                case GridItemType.AlternatingItem: 
                    string currHazMat = ( ( HazardMaterialsList )e.Item.DataItem ).Material; 
                    if ( currHazMat != _previousHazerdousMaterial ) 
                    { 
                        _previousHazerdousMaterial = currHazMat; 
                        _hazMatTableCell = ( ( GridDataItem )e.Item )["Material"]; 
                        //set the horizontal border of the first cell 
                        _hazMatTableCell.Style.Add( "border-top""solid 1px #ededed" ); 
                    } 
                    else 
                    { 
                        ( ( GridDataItem )e.Item )["Material"].Visible = false
                        //set the border of the second cell.   
                        //Since the first cell is hidden, styles for the first cell are applied to this cell 
                        //which hides the left border by default.  This will force the left border to show. 
                        ( ( GridDataItem )e.Item )["Class"].Style.Add( "border-left""solid 1px #ededed" ); 
 
                        if ( _hazMatTableCell.RowSpan == 0 ) 
                            _hazMatTableCell.RowSpan = 2; 
                        else 
                            _hazMatTableCell.RowSpan++; 
                    } 
 
                    break
            } 
        } 

0
Trung Nguyen
Top achievements
Rank 1
answered on 01 Sep 2009, 09:20 AM
i solved problem, thanks for all.

this code to merge row

public static void MergeRows(RadGrid RadGrid1) 
        { 
            for (int i = RadGrid1.Items.Count - 2; i > 0; i--) 
            { 
                if (RadGrid1.Items[i][RadGrid1.Columns[0]].Text == RadGrid1.Items[i - 1][RadGrid1.Columns[0]].Text) 
                { 
                    RadGrid1.Items[i - 1][RadGrid1.Columns[0]].RowSpan = RadGrid1.Items[i][RadGrid1.Columns[0]].RowSpan < 2 ? 2 : RadGrid1.Items[i][RadGrid1.Columns[0]].RowSpan + 1;                     
                    RadGrid1.Items[i][RadGrid1.Columns[0]].Visible = false
                    //RadGrid1.Items[i][RadGrid1.Columns[0]].Text = "&nbsp;";  
                } 
            } 
            //To mau lai cho Radgird 
            foreach (GridDataItem dataItem in RadGrid1.Items) 
            { 
                foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns) 
                { 
                    //if (dataItem[col.UniqueName].Text == string.Empty) 
                    dataItem[col.UniqueName].Style.Add("border-left", "solid 1px #ededed"); 
                } 
            }    
        } 

0
Minh Đinh
Top achievements
Rank 1
answered on 16 Sep 2010, 08:17 AM
Thanks, that's what exactly what i've been looking for.

Minh
0
Dhamodharan
Top achievements
Rank 1
answered on 02 Oct 2012, 10:46 AM
Hi ,
       Can we merge rows of radgrid through client side (javascript)..?
0
Marin
Telerik team
answered on 05 Oct 2012, 08:16 AM
Hello,

 This will be a cumbersome approach because you will have to modify the DOM tree dynamically on the client via javascript by changing row and col spans and removing cells from the table. So it is not recommended.

Regards,
Marin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
madhavi
Top achievements
Rank 1
answered on 03 Nov 2014, 04:46 AM
we are dynamically creating RadGrid.

We are merging rows similar rows in radgrid but it is working on postback only. It does not work first time page load.

Please help me with this problem.
0
Marin
Telerik team
answered on 06 Nov 2014, 07:45 AM
Hi,

Page_Load is a too early event and the grid will not yet be rendered initially without postback. That's why it is recommended to use a later event like Page_PreRender or ItemCreated as shown in the code snippets from previous posts in the thread.

Regards,
Marin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Trung Nguyen
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Trung Nguyen
Top achievements
Rank 1
Andy Spears
Top achievements
Rank 1
Minh Đinh
Top achievements
Rank 1
Dhamodharan
Top achievements
Rank 1
Marin
Telerik team
madhavi
Top achievements
Rank 1
Share this question
or