I have the GridView the produces the following rows:
Column0
Column1
Column2
Group A
Report A
Link 1
Group C
Report A
Link 1
Is it possible to hide a row in gridview when a repeated value occurs in Column1? In order to produce the below result:
Column0
Column1
Column2
Group A
Report A
Link 1
Code page:
Imports System.Data.SqlClient
Imports System.Web.Configuration
Public Class _default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub GridView1_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GridView1.RowDataBound
Dim hLink As HyperLink = TryCast(e.Row.FindControl("hLnk"), HyperLink)
Dim lblApp As Label = TryCast(e.Row.FindControl("lblAppName"), Label)
Dim lblGrp As Label = TryCast(e.Row.FindControl("lblGroup"), Label)
Dim lblCod As Label = TryCast(e.Row.FindControl("lblCode"), Label)
Try
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Visible = IsInGroup(lblGrp.Text.Trim())
End If
Catch ex As Exception
End Try
End Sub
Public Function IsInGroup(ByVal GroupName As String) As Boolean
Dim MyIdentity As System.Security.Principal.WindowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent()
Dim MyPrincipal As System.Security.Principal.WindowsPrincipal = New System.Security.Principal.WindowsPrincipal(MyIdentity)
Return MyPrincipal.IsInRole(GroupName)
End Function
End Class
If e.Row.RowType = DataControlRowType.DataRow Then
Dim hLink As HyperLink = TryCast(e.Row.FindControl("hLnk"), HyperLink)
Dim lblApp As Label = TryCast(e.Row.FindControl("lblAppName"), Label)
Dim lblGrp As Label = TryCast(e.Row.FindControl("lblGroup"), Label)
Dim lblCod As Label = TryCast(e.Row.FindControl("lblCode"), Label)
If Not ViewState("col1") = Nothing Then
If ViewState("col1") = lblGrp.Text Then
e.Row.Visible = False
Else
ViewState("col1") = lblGrp.Text
End If
Else
ViewState("col1") = lblGrp.Text
End If
End If
Programming to simplify, don't look for difficult way
Suwandi - Non Graduate Programmer
Member
24 Points
132 Posts
How can I hide row in a Gridview based on repeated value?
Apr 18, 2018 07:23 PM|Matt99|LINK
I have the GridView the produces the following rows:
Is it possible to hide a row in gridview when a repeated value occurs in Column1? In order to produce the below result:
Code page:
I apprciate any help, thanks in advance.
All-Star
52202 Points
15507 Posts
Re: How can I hide row in a Gridview based on repeated value?
Apr 18, 2018 08:11 PM|oned_gk|LINK
Suwandi - Non Graduate Programmer