Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. [Message Deleted]

[Message Deleted]

Scheduled Pinned Locked Moved C#
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nesaver85
    wrote on last edited by
    #1

    [Message Deleted]

    A 1 Reply Last reply
    0
    • N nesaver85

      [Message Deleted]

      A Offline
      A Offline
      Anoop Unnikrishnan
      wrote on last edited by
      #2

      Drag and drop a GridView and name it as GridView1 Try the below code for merging the header protected void Page_Load(object sender, EventArgs e) { DataTable dt = new DataTable("Employee"); //Name Age Gender Mobile Phone Email dt.Columns.Add("Name"); dt.Columns.Add("Age"); dt.Columns.Add("Gender"); dt.Columns.Add("Mobile"); dt.Columns.Add("Phone"); dt.Columns.Add("Email"); dt.Rows.Add("Anoop", "25", "Male", "996633352", "02255566", "anoopukrish@gmail.com"); GridView1.DataSource = dt; GridView1.DataBind(); } protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Header) { GridView gridView = (GridView)sender; GridViewRow gridViewRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert); TableCell tableCell = new TableCell(); //add Personal Info tableCell.Text = "Personal Info"; tableCell.Attributes.Add("style", "text-align: center"); tableCell.ColumnSpan = 3; gridViewRow.Cells.Add(tableCell); //Add Contact Info tableCell = new TableCell(); tableCell.Attributes.Add("style", "text-align: center"); tableCell.Text = "Contact Info"; tableCell.ColumnSpan = 3; gridViewRow.Cells.Add(tableCell); GridView1.Controls[0].Controls.AddAt(0, gridViewRow); } } ... There by u get the desired output...

      J 1 Reply Last reply
      0
      • A Anoop Unnikrishnan

        Drag and drop a GridView and name it as GridView1 Try the below code for merging the header protected void Page_Load(object sender, EventArgs e) { DataTable dt = new DataTable("Employee"); //Name Age Gender Mobile Phone Email dt.Columns.Add("Name"); dt.Columns.Add("Age"); dt.Columns.Add("Gender"); dt.Columns.Add("Mobile"); dt.Columns.Add("Phone"); dt.Columns.Add("Email"); dt.Rows.Add("Anoop", "25", "Male", "996633352", "02255566", "anoopukrish@gmail.com"); GridView1.DataSource = dt; GridView1.DataBind(); } protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Header) { GridView gridView = (GridView)sender; GridViewRow gridViewRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert); TableCell tableCell = new TableCell(); //add Personal Info tableCell.Text = "Personal Info"; tableCell.Attributes.Add("style", "text-align: center"); tableCell.ColumnSpan = 3; gridViewRow.Cells.Add(tableCell); //Add Contact Info tableCell = new TableCell(); tableCell.Attributes.Add("style", "text-align: center"); tableCell.Text = "Contact Info"; tableCell.ColumnSpan = 3; gridViewRow.Cells.Add(tableCell); GridView1.Controls[0].Controls.AddAt(0, gridViewRow); } } ... There by u get the desired output...

        J Offline
        J Offline
        jp2code
        wrote on last edited by
        #3

        Just a note: The original question was how to merge a *DataGridView* Control. The answer above appears to show how to merge a *GridView* Control. The two controls are not the same.

        Avoid Sears Home Improvement!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups