Group Gridview Columns in asp.net
Imports System.Data
Imports System.Web.UI.WebControls
Partial Class VBCode
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
BindGridview()
End If
End Sub
Protected Sub BindGridview()
Dim dt As New DataTable()
dt.Columns.Add("UserId", GetType(Int32))
dt.Columns.Add("UserName", GetType(String))
dt.Columns.Add("Education", GetType(String))
dt.Columns.Add("Location", GetType(String))
dt.Rows.Add(1, "SureshDasari", "B.Tech", "Chennai")
dt.Rows.Add(2, "MadhavSai", "MBA", "Nagpur")
dt.Rows.Add(3, "MaheshDasari", "B.Tech", "Nuzividu")
dt.Rows.Add(4, "SureshDasari", "B.Tech", "Chennai")
gvDetails.DataSource = dt
gvDetails.DataBind()
End Sub
Protected Sub gvDetails_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
Dim gvRow__1 As GridViewRow = e.Row
If gvRow__1.RowType = DataControlRowType.Header Then
Dim gvrow__2 As New GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert)
Dim cell0 As New TableCell()
cell0.Text = "Age Group"
cell0.HorizontalAlign = HorizontalAlign.Center
cell0.ColumnSpan = 2
Dim cell1 As New TableCell()
cell1.Text = "No. Of Employees"
cell1.HorizontalAlign = HorizontalAlign.Center
cell1.ColumnSpan = 2
gvrow__2.Cells.Add(cell0)
gvrow__2.Cells.Add(cell1)
gvDetails.Controls(0).Controls.AddAt(0, gvrow__2)
End If
End Sub
End Class
0 comments:
Speak up your mind
Tell us what you're thinking... !