Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good day!

I created a hierarchal gridview in the gridview created inside a the gridview i wanted to hide a specific column say column(0). I could not make it happen. Can anyone help me?

here is my code

VB
Protected Sub Gridview1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) 
        If e.CommandName = "Expand" Then
            Dim gv As GridView = sender
                          
            con.Open()
            
                Dim ds As New DataSet
                Dim sql As String
                sql = "SELECT * From [someTable]"
                Dim adp As New SqlDataAdapter(Sql, con)
                adp.Fill(ds,"tblData")
                gv.Rows(rowindex).Cells(5).Controls.Add(gdv)
		'I tried this codes to hide the first column but nothing happens
		ds.tables("tblData").Columns(0).ColumnMapping=Data.MappingType.Hidden
		Dim gdv as New Gridview
                Dim gdv As New GridView
                gdv.DataSource = ds
                gdv.DataBind()
		gv.Rows(rowindex).Cells(5).Controls.Add(gdv)
End sub
Posted

I manage to create a solution to my on problem;

here is the solution.

VB
Protected Sub Gridview1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs)
        If e.CommandName = "Expand" Then
            Dim gv As GridView = sender

            con.Open()

                Dim ds As New DataSet
                Dim sql As String
                sql = "SELECT * From [someTable]"
                Dim adp As New SqlDataAdapter(Sql, con)
                adp.Fill(ds,"tblData")
                gv.Rows(rowindex).Cells(5).Controls.Add(gdv)
                Dim gdv As New GridView
                gdv.ID="GDV"
                gdv.DataSource = ds
                gdv.AutogenerateColumns=True
                AddHandler gdv.RowCreated, Addressof GDV_RowCreated
                gdv.DataBind()
                gv.Rows(rowindex).Cells(5).Controls.Add(gdv)
End sub

Protected Sub GDV_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
    e.Row.Cells(0).Visible=False
End sub
 
Share this answer
 
You can write your code in row created
C#
GridView1.Columns[0].Visible = false
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900