Thursday, August 30, 2012

How to Add multiple Headers to gridview in Asp.Net using C#


Hear i am going to explain how to add multiple Headers to Gridview in ASp.Net using C#
as shown below two examples...








Ex 1:


       protected void ExpGvToPDFControl_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                GridView HeaderGrid = (GridView)sender;
                GridViewRow HeaderGridRow = new
               GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
                TableCell HeaderCell = new TableCell();
                HeaderCell.HorizontalAlign = HorizontalAlign.Center;
                HeaderCell.Text = "Sample Heading When Exporting";
                HeaderCell.ColumnSpan = 8;
                HeaderGridRow.Cells.Add(HeaderCell);
                ExpGvToPDFControl.Controls[0].Controls.AddAt(0, HeaderGridRow);

            }
        }

Ex 2 :

 
       protected void ExpGvToPDFControl_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                GridView HeaderGrid = (GridView)sender;
                GridViewRow HeaderGridRow = new
              GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
                TableCell HeaderCell = new TableCell();
                HeaderCell.HorizontalAlign = HorizontalAlign.Center;
                HeaderCell.Text = "Half Part 1";
                HeaderCell.ColumnSpan = 4;
                HeaderGridRow.Cells.Add(HeaderCell);

                HeaderCell = new TableCell();
                HeaderCell.HorizontalAlign = HorizontalAlign.Center;
                HeaderCell.Text = "Half Part 2";
                HeaderCell.ColumnSpan = 4;
                HeaderGridRow.Cells.Add(HeaderCell);

                ExpGvToPDFControl.Controls[0].Controls.AddAt(0, HeaderGridRow);

            }
       }

1 comment:

  1. HI Whats is the use of ExpGvToPDFControl_RowCreated Event What it really does
    and Where ur doing this Exporting Process Plz Elaborate

    ReplyDelete