troubleshooting Question

Datagrid - Sort and Show Webding font in header

Avatar of tbaseflug
tbaseflugFlag for United States of America asked on
Fonts TypographyASP.NET
2 Comments1 Solution634 ViewsLast Modified:
I have the folllwing code- which binds, formats and sorts my datagrid as expected - however, I am trying to get the webdings "icon" to display in the header(s) when sorted by that column - but form some reason it is show displaying - everyhting else works as expected:
---------------------------------------------------------------------------
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        'If Not IsPostBack Then
        BindGrid()
        'End If
    End Sub

    Sub BindGrid()
        Dim dv As DataView = DATA.Tasks_Completed2
        With dgCompleted
            .AutoGenerateColumns = False
            .DataSource = dv
            .DataBind()
            .AllowSorting = True
            .CellPadding = 3
            .CellSpacing = 1
            .Width = Unit.Pixel(770)
            .BorderWidth = Unit.Pixel(0)
            .CssClass = "Grid"
            .HeaderStyle.CssClass = "GridHeader"
            .AlternatingItemStyle.CssClass = "AlternateRow"
        End With
    End Sub

    Private Sub dgCompleted_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles dgCompleted.SortCommand
        Dim _sortExpr As String = e.SortExpression
        Dim _dv As DataView = DATA.Tasks_Completed2
        If ViewState("SortOrder3") Is Nothing OrElse _
        ViewState("SortOrder3") = "" OrElse ViewState("SortOrder3") = "ASC" Then
            _dv.Sort = _sortExpr & " DESC"
            ViewState("SortOrder3") = "DESC"
        Else
            _dv.Sort = _sortExpr
            ViewState("SortOrder3") = "ASC"
        End If
        ViewState("SortExpr3") = _sortExpr.ToLower
        Me.dgCompleted.DataSource = _dv
        Me.dgCompleted.DataBind()
    End Sub

    Private Sub dgCompleted_ItemDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgCompleted.ItemDataBound
        Dim img As System.Web.UI.WebControls.Image
        Select Case e.Item.ItemType
            Case ListItemType.Header
                e.Item.Cells(0).Attributes.Add("align", "left")
                e.Item.Cells(1).Attributes.Add("align", "left")
                e.Item.Cells(2).Attributes.Add("align", "Left")
                e.Item.Cells(4).Attributes.Add("align", "center")
            Case ListItemType.AlternatingItem, ListItemType.Item
                If e.Item.Cells(3).Text = "No Response" Then
                    'e.Item.Cells(3).ForeColor = Color.FromArgb(153, 0, 0)
                    'e.Item.Cells(3).Font.Bold = True
                    'e.Item.Cells(3).Attributes.Add("align", "middle")
                    img = CType(e.Item.Cells(4).Controls(1), System.Web.UI.WebControls.Image)
                    img.ImageUrl = "images/square_redS.gif"
                    e.Item.Cells(4).Attributes.Add("align", "middle")
                Else
                    img = CType(e.Item.Cells(4).Controls(1), System.Web.UI.WebControls.Image)
                    img.ImageUrl = "images/square_greenS.gif"
                    e.Item.Cells(4).Attributes.Add("align", "middle")
                End If
        End Select
    End Sub

    Private Sub dgCompleted_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgCompleted.ItemCreated
        Select Case e.Item.ItemType
            Case ListItemType.Header
                Dim lbl As New System.Web.UI.WebControls.Label
                lbl.Font.Name = "webdings"
                If ViewState("SortExpr3") Is Nothing Then
                    Return
                Else
                    If ViewState("SortOrder3") = "DESC" Then
                        lbl.Text = "6"
                    Else
                        lbl.Text = "5"
                    End If
                    Select Case ViewState("SortExpr3")
                        Case "GroupName"
                            e.Item.Cells(0).Controls.Add(lbl)
                        Case "Description"
                            e.Item.Cells(1).Controls.Add(lbl)
                        Case "OwnerName"
                            e.Item.Cells(2).Controls.Add(lbl)
                        Case "Status"
                            e.Item.Cells(4).Controls.Add(lbl)
                    End Select
                End If
        End Select
    End Sub
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros