GridView Hide Column

GridView is used in showing information in a tabular form, GridView replaced the Datagrid which was used in asp.net 1.1, if you are working in asp.net 2.0 then you are facing a problem which is that you can not hide a particular column if you want but in asp.net 1.1 you can do it by simply making the visible property false,hat it so simple but in asp.net 2.0 its not so easy, but if problem is there, chances of solution is also there I will tell you 2 method to deal with this type of problem 1). Create the Row Created event handler and do the following: Public Sub myGrid_OnRowCreated(ByVal sender As Object, ByVal e As Web.UI.WebControls.GridViewRowEventArgs) Handles myGrid.RowCreated 'Those columns you don't want to display you config here, 'you could use a for statement if you have many e.Row.Cells(1).Visible = False End Sub 2) Public Sub myTestFunction() 'To hide a column, set its width to zero or use MappingType Dim strCON As String = "" Dim strQuery As String = "" Dim da As Data.SqlClient.SqlDataAdapter Dim ds As Data.DataSet Try Dim conn As New Data.SqlClient.SqlConnection(strCON) da = New Data.SqlClient.SqlDataAdapter(strQuery, CON) ds = New Data.DataSet da.Fill(ds, "tblData") conn.Close() Catch ex As Exception 'Do error handling here... End Try 'Here you can HIDE the Column ds.Tables("tblData").Columns(colIndex).ColumnMapping = Data.MappingType.Hidden myGrid.DataSource = ds.Tables("tblData") End Sub by use these methods we can hide the columns of GridView as we wish. Happy coding About the author: Planet Source Code is a place for all developer providing free source codes, articles, complete projects,complete application in PHP, C/C++, Javascript, Visual Basic, Cobol, Pascal, ASP/VBScript, AJAX, SQL, Perl, Python, Ruby, Mobile Development

Comments

Submitted byAnonymous (not verified)on Fri, 02/05/2010 - 17:16

how to get minimum column width in vb 2008

Add new comment