Skip to main content

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

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

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

how to get minimum column width in vb 2008

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.