.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Merge Column

Posted By: DPK     Posted Date: September 30, 2008    Points:2   Category :ASP.Net
Hello friends..

anyone has idea how to merge two columns in DATAGRID.

thanks!!

Responses
Author: Amit Mehra             
Posted Date: September 30, 2008     Points: 5   

Hi,
Why dont you merge column in the SQL Query itself.

Like this and this approch is best

Select (First_Name +' '+ Last_Name) as Name from Table_name.

But if you want to merge the Datagrid Heder column the follow this articles.

http://www.codeproject.com/KB/webforms/MergeHeader.aspx

Thanks,
Amit
Please "Mark As Answer " if this post help you.
Author: rasikpatel             
Posted Date: October 03, 2008     Points: 5   

You have to do set the Colspan attribute to cells in order to merge the columns in datagrid as per your requirement.

you have to do in itemcreated event of the datagrid.

Author: Athira Sreejith             
Posted Date: February 24, 2009     Points: 5   

Hi..

protected void grdExpense_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
//Build custom header.
GridView oGridView = (GridView)sender;
GridViewRow oGridViewRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
TableCell oTableCell = new TableCell();

oTableCell.Text = "Employee";
oTableCell.ColumnSpan = 2;
oTableCell.HorizontalAlign = HorizontalAlign.Left;
oTableCell.Style.Add("Padding-left", "50px");
oGridViewRow.Cells.Add(oTableCell);

oTableCell = new TableCell();
oTableCell.Text = ">3 Visit";
oTableCell.ColumnSpan = 3;
oTableCell.HorizontalAlign = HorizontalAlign.Left;
oTableCell.Style.Add("Padding-left", "30px");
oGridViewRow.Cells.Add(oTableCell);

oTableCell = new TableCell();
oTableCell.Text = "3 Visit";
oTableCell.ColumnSpan = 3;
oTableCell.HorizontalAlign = HorizontalAlign.Left;
oTableCell.Style.Add("Padding-left", "30px");
oGridViewRow.Cells.Add(oTableCell);

oTableCell = new TableCell();
oTableCell.Text = "2 Visit";
oTableCell.ColumnSpan = 3;
oTableCell.HorizontalAlign = HorizontalAlign.Left;
oTableCell.Style.Add("Padding-left", "30px");
oGridViewRow.Cells.Add(oTableCell);

oTableCell = new TableCell();
oTableCell.Text = "1 Visit";
oTableCell.ColumnSpan = 3;
oTableCell.HorizontalAlign = HorizontalAlign.Left;
oTableCell.Style.Add("Padding-left", "30px");
oGridViewRow.Cells.Add(oTableCell);

oTableCell = new TableCell();
oTableCell.Text = "Not Visit";
oTableCell.ColumnSpan = 3;
oTableCell.HorizontalAlign = HorizontalAlign.Left;
oTableCell.Style.Add("Padding-left", "30px");
oGridViewRow.Cells.Add(oTableCell);
oGridView.Controls[0].Controls.AddAt(0, oGridViewRow);
}
}



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend