3 Replies - 6379 Views - Last Post: 08 February 2012 - 07:01 PM Rate Topic: -----

#1 mrburnttoast  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 14
  • Joined: 28-December 11

Gridview row bold on rowDataBound not working

Posted 06 February 2012 - 09:10 PM

I am having a problem with adding style to a gridview row. I have a field called "IsBold" which is a varchar populated with either "Y" or "N". I want the text in the row to be bold if the value is "Y". The data populates just fine but will not "bold". I have tried everything, including changing the cell index number just in case I had it wrong. Every example I have found on the web has shown basically the same code I have. Can anyone notice what I am doing wrong here?

Here is the code from the .aspx page for the gridview
<asp:GridView ID="gvManagement" runat="server" CssClass="gridstyle"  AlternatingRowStyle-CssClass="altrow"
        DataSourceID="" AutoGenerateColumns="False" OnRowDataBound="gvManagement_RowDataBound">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:LinkButton ID="btnEdit" runat="server" CausesValidation="false" CommandName="Edit" Text="Edit" />
            </ItemTemplate>
            <EditItemTemplate>
                <asp:LinkButton ID="btnUpdate" runat="server"  CommandName="Update" Text="Update"/>
                <asp:LinkButton ID="btnCancel" runat="server" CommandName="Cancel" Text="Cancel" />
            </EditItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:LinkButton ID="btnDelete" runat="server" CausesValidation="false" CommandName="Delete" Text="Delete" />
            </ItemTemplate>
            <EditItemTemplate>
            
            </EditItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="ID" ReadOnly="true" HeaderText="ID"/>
        <asp:BoundField DataField="Sequence" ReadOnly="true" HeaderText="Sequence"/>
        <asp:BoundField DataField="Name" ReadOnly="true" HeaderText="Name" />
        <asp:BoundField DataField="Title" ReadOnly="true" HeaderText="Title" />
        <asp:BoundField DataField="Division" ReadOnly="true" HeaderText="Division Name" />
        <asp:BoundField DataField="MailDrop" ReadOnly="true" HeaderText="Mail Drop" />
        <asp:BoundField DataField="Phone" ReadOnly="true" HeaderText="Telephone Number" />
        
        <asp:TemplateField HeaderText="Bold" >
            <ItemTemplate>
                <%# Eval("IsBold")%>
            </ItemTemplate>
            <EditItemTemplate>
                <asp:CheckBox ID="chkBoxBold" runat="server" Width="20px" Text='<%# Eval("IsBold")%>'/>
            </EditItemTemplate>
        </asp:TemplateField>
        
     </Columns>

    </asp:GridView>



...and here is the RowDataBound event from the code behind.

Protected Sub gvManagement_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvManagement.RowDataBound

        If e.Row.RowType = DataControlRowType.DataRow Then
            If e.Row.Cells(9).Text = "Y" Then
                e.Row.Font.Bold = True
            End If

        End If

    End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: Gridview row bold on rowDataBound not working

#2 ajwsurfer  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 21
  • View blog
  • Posts: 373
  • Joined: 24-October 06

Re: Gridview row bold on rowDataBound not working

Posted 08 February 2012 - 10:34 AM

Probably the easiest way to deal with this is to replace
<%# Eval("IsBold")%>

with
<%# MakeBold(Eval("IsBold"))%>

and add this function to the code behind class
  Protected Function MakeBold(ByVal IsBold As Object) As String
    Return "<span " & IIf(IsBold.ToString = "Y", "style=""font-weight:bold;"">", ">") & _
           "IsBold.ToString & "</span>"
  End Function


Was This Post Helpful? 0
  • +
  • -

#3 mrburnttoast  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 14
  • Joined: 28-December 11

Re: Gridview row bold on rowDataBound not working

Posted 08 February 2012 - 06:41 PM

Thank you ajwsurfer, that sort of worked. I can at least see that it is checking the condition and is making that field bold. However, is there a way that I could make the text from each field of the row bold rather than the IsBold field?
Was This Post Helpful? 0
  • +
  • -

#4 mrburnttoast  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 14
  • Joined: 28-December 11

Re: Gridview row bold on rowDataBound not working

Posted 08 February 2012 - 07:01 PM

I changed the template field for "IsBold" into a bound field and changed the cell index to 8 and it worked exactly as I needed it to. I want the field to be a template field because I need a checkbox in edit mode. Any ideas?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1