Hidden column in datagrid

A

amos

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

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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,078
Latest member
MakersCBDBlood

Latest Threads

Top