Home All Groups Group Topic Archive Search About
Author
27 Mar 2006 7:55 AM
amos
I have a datasource in datatable or dataset I want to hide one of the column
how can I do this?
thanks.

Author
27 Mar 2006 3:11 PM
Phillip Williams
The datagrid allows you either to specify columns (using templates) to
display or to have the columns generated dynamically (by setting the
AutoGenerateColumns property value to true). If you list your columns, then
you can change the style for each column while handling the ItemDataBound
event

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
DataGridItemEventArgs) Handles dgProdPercentDim.ItemDataBound,
dgProdPercentPet.ItemDataBound
       If e.Item.ItemType = ListItemType.Item Or _
               e.Item.ItemType = ListItemType.AlternatingItem Or _
               e.Item.ItemType = ListItemType.Header Then
            Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView)
            Dim i As Integer
            For i = 0 To drv.Row.Table.Columns.Count - 1
                Select Case drv.Row.Table.Columns(i).ColumnName.ToUpper
                    Case "SUPPLIER", "PRODID", "DESTINATION"
                        'hide the cells that correspond to those datatable
field names
                        e.Item.Cells(i).CssClass = "Hidden"
                    Case Else
                        'assign a different style
                        e.Item.Cells(i).CssClass = "RightAlign"
                End Select

            Next

        End If
    End Sub

Then in your CSS you would define Hidden as
<style>
..Hiden{display:none;}
</style>
Show quoteHide quote
"amos" wrote:

> I have a datasource in datatable or dataset I want to hide one of the column
> how can I do this?
> thanks.