I have autogenerated columns here from visitid and so on. The first column however was a templatefield. now I wanted to hide VisitID. I tried this code but it didn't work. I am using vb as my codebehind
e.Row.Cells(1).Visible = False
I have tried several ways but also ended with this code and it worked finally I just added a condition. I'm sorry maybe I lacked information. I had a pagination in the gridview.. Here was my working code.
Protected Sub Gdvisitor_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles Gdvisitor.RowCreated
If (e.Row.Cells.Count > 1) Then
e.Row.Cells(1).Visible = False
End If
End Sub
At first it was "....cells.count < 0" and that didn't work the index was still out of range but when I changed it to 1. It worked. I think the pagination has something to do with it. I'm not sure though... Thank you for all the help
要隐藏列,您需要将列设置为false,而不是单元格。
gridView1.Columns(1).Visible = False
尝试这个 ...
GridView.Columns(1).Visible = false
Try this...
gridview name.columns(column number).visible=false;
If u want to hide the 3rd column use the above code as:
gridview name.columns(3).visible=false;
Autogeneraterd grids' columns cannot be hidden. If you do a check like dg.columns.count
you'll get 0
instead of 6
.
Use a template column for each one or do this using jQuery.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.