C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » ASP.NET GridView »

Merging Grid View Headers


Posted Date: 11 Nov 2008    Resource Type: Code Snippets    Category: ASP.NET GridView
Author: Gnana Prakash Member Level: Gold    
Rating: 1 out of 5Points: 10



Below code will explain the how to merge two column in the grid view.

Desing Code
----------


<asp:GridView ID="dvMergingHeader" runat="server" OnRowCreated="dvMergingHeader_ItemCreated" align="center" AutoGenerateColumns="false" BorderStyle="None" BorderWidth="1px" CellPadding="4" Width="100%">
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<RowStyle CssClass="ctext" BackColor="LightCyan" Font-Bold="False" VerticalAlign="Top" />
<HeaderStyle BackColor="gray" Font-Bold="True" CssClass="text" ForeColor="white" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center" VerticalAlign="Middle" />

<asp:BoundField DataField=" Column1" HeaderText="Column1">
<ItemStyle HorizontalAlign="Left" VerticalAlign="top" />
</asp:BoundField>
<asp:BoundField DataField=" Column2" HeaderText="Column2">
<ItemStyle HorizontalAlign="Left" VerticalAlign="top" />
</asp:BoundField>
<asp:BoundField DataField=" Column3" HeaderText="Column3">
<ItemStyle HorizontalAlign="Left" VerticalAlign="top" />
</asp:BoundField>
<asp:BoundField DataField=" Column4" HeaderText="Column4">
<ItemStyle HorizontalAlign="Left" VerticalAlign="top" />
</asp:BoundField>
</asp:GridView>



Code Behind
-------------



protected void dvMergingHeader_ItemCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
//custom header.
GridView gvHeader = (GridView)sender;
GridViewRow gvHeaderRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
TableCell tc1 = new TableCell();

// First Merged column
tc1.Text = "Merged Column1";
tc1.ColumnSpan = 2;
tc1.BackColor = System.Drawing.Color.Brown;

gvHeaderRow.Cells.Add(tc1l);

// Second Merged column
tc1 = new TableCell();
tc1.Text = "Merged Column2";
tc1.ColumnSpan = 2;
gvHeaderRow.Cells.Add(tc1);

gvHeader.Controls[0].Controls.AddAt(0, gvHeaderRow);

}
}








Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Two Headers in Grid View  .  Merging Header column  .  Merging Grid View Headers  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Edit,Update,Cancel,Delete and multiple checkbox select to delete in vs2003 DataGrid?
Previous Resource: Merging Grid View Header
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET GridView


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use