keymac
asked on
How do I hide a column of a Gridview at runtime
I am creating a gridview at runtime but don't want all the columns to be shown, ie the key information for the row of data I am showing. I know I can do this
gridview1.column.item(0).v isible = false
but although the column is not shown it also does not have the data in the column either and since I need to know the key data for processing the selected item from the grid, the above does not work for me
gridview1.column.item(0).v
but although the column is not shown it also does not have the data in the column either and since I need to know the key data for processing the selected item from the grid, the above does not work for me
To hide a column at runt time you can hook up to the GridView’s RowDataBound event and set the Visible property of the cell you want to hide to false: protected void GridView1_RowDataBound(obj ect sender, GridViewRowEventArgs e) { e.Row.Cells[0].Visible = false; }...
ASKER
As I said in the question, that approach dos not work. I need the column to be hidden not invisible. If it is invisible it is not available as data in the grid, ie I want the column to still have data bound to it but to be hidden to the viewer.
have you tried this
protected void GridView1_RowDataBound(obj ect sender, GridViewRowEventArgs e) { e.Row.Cells[0].Visible = false;
protected void GridView1_RowDataBound(obj
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
in vb.net
Protected Sub GridView1_RowDataBound(sen der As Object, e As GridViewRowEventArgs)
e.Row.Cells(0).Visible = False
End Sub
Protected Sub GridView1_RowDataBound(sen
e.Row.Cells(0).Visible = False
End Sub
Just use the Datakeyname property of the gridview to store the value of key u use 4 processing the row.
ASKER
Magnificent
If e.Row.RowType = DataControlRowType.Header Then
e.Row.Controls(6).Visible = False
End If
If e.Row.RowType = DataControlRowType.DataRow
e.Row.Controls(6).Visible = False
End If