Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide column of an autogenerated gridview with one templatefield

Tags:

asp.net

vb.net

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

enter image description here

like image 586
Ley47 Avatar asked Feb 01 '26 19:02

Ley47


1 Answers

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

like image 128
Ley47 Avatar answered Feb 03 '26 09:02

Ley47



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!