Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Gridview VB.NET
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
 
 
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 22-Apr-12 20:33pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I manage to create a solution to my on problem;
 
here is the solution.
 
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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You can write your code in row created
GridView1.Columns[0].Visible = false
  Permalink  
v2

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



Advertise | Privacy | Mobile
Web03 | 2.8.141015.1 | Last Updated 13 Jun 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100