ProperCasing fields in a GridView in C#

I have a C# ASP.Net 2.0 Gridview populated from a SQL stored procedure. The records in the database are mostly in ALL CAPS, and some are Proper Cased. I want to get ALL the fields to be Proper Cased in the GridView. I tried to do this with CSS, but it didn't work.

Some of the fields are BoundFields, and a couple are TemplateFields. How can I get them all ProperCased?
.salesdirgrid
{
    font-size: smaller;
    color: #1c66af;
    font-family: Tahoma, Verdana, Sans-Serif;
    background-image: none;
    text-transform: capitalize;
}
 
-----------------------------------------------------------
 
<asp:GridView id="gvResult" runat="server" Width="100%" CssClass="salesdirgrid" 
            AllowPaging="True" CellPadding="1" AllowSorting="True"
            OnRowDataBound="gvResult_RowDataBound" OnPageIndexChanging="gvResult_PageIndexChanging" DataSourceID="SqlDataSource1" AutoGenerateColumns="False" DataKeyNames="Terr,Mkt,Agtno5,Fname,Lname,DBA,Street,City,State,Zip,Booth,EmplDate,TermDate,PrefPhone,Ceasar,County,ACT,Sat_Type">
			<HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#1C66AF" />
			<FooterStyle ForeColor="#4A3C8C" BackColor="#1C66AF" />
			<PagerStyle HorizontalAlign="Left" ForeColor="White" BackColor="#1C66AF" />
            <Columns>
                <asp:BoundField DataField="Terr" HeaderText="T" ReadOnly="True" SortExpression="[Terr]" />
                <asp:BoundField DataField="Mkt" HeaderText="M" ReadOnly="True" SortExpression="[Mkt]" />
                <asp:HyperLinkField DataNavigateUrlFields="AgtNo5" DataNavigateUrlFormatString="http://road/aotemail/email.aspx?to=A0{0}@allstate.com&amp;body=Enter%20message%20here"
                    DataTextField="AgtNo5" HeaderText="Agent #" SortExpression="[Agtno5]" Target="_blank" />
                <asp:TemplateField HeaderText="First Name" SortExpression="[FName]">
                    <EditItemTemplate>
                        <asp:TextBox ID="txtFname" Text='<%# Bind("FName") %>' runat="server"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lblFname" Text='<%# Eval("FName") %>' runat="server"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Last Name" SortExpression="[LName]">
                    <EditItemTemplate>
                        <asp:TextBox ID="txtLname" Text='<%# Bind("LName") %>' runat="server"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lblLname" Text='<%# Eval("LName") %>' runat="server"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Agency Name" SortExpression="[DBA]">
                    <EditItemTemplate>
                        <asp:TextBox ID="txtDBA" Text='<%# Bind("DBA") %>' runat="server"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lblDBA" Text='<%# Eval("DBA") %>' runat="server"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Street" SortExpression="[Street]">
                    <EditItemTemplate>
                        <asp:TextBox ID="txtStreet" Text='<%# Bind("Street") %>' runat="server"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lblStreet" Text='<%# Eval("Street") %>' runat="server"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="City" SortExpression="[City]">
                    <EditItemTemplate>
                        <asp:TextBox ID="txtCity" Text='<%# Bind("City") %>' runat="server"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lblCity" Text='<%# Eval("City") %>' runat="server"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="State" HeaderText="St" ReadOnly="True" SortExpression="[State]" />
                <asp:BoundField DataField="Zip" HeaderText="ZIP" ReadOnly="True" SortExpression="[Zip]" />
                <asp:BoundField DataField="Booth" HeaderText="Booth" ReadOnly="True" SortExpression="[Booth]" />
                <asp:BoundField DataField="EmplDate" DataFormatString="{0:d}" HtmlEncode="false" HeaderText="Hire Dt"
                    ReadOnly="True" SortExpression="[EmplDate]" />
                <asp:BoundField DataField="TermDate" DataFormatString="{0:d}" HtmlEncode="false" HeaderText="Term Dt"
                    ReadOnly="True" SortExpression="[TermDate]" />
                <asp:BoundField DataField="PrefPhone" DataFormatString="{0:(###) ###-####}" HtmlEncode="false" HeaderText="Phone" 
                    ReadOnly="true" SortExpression="[PrefPhone]" />
                <asp:TemplateField HeaderText="Ceasar" SortExpression="[Ceasar]">
                    <EditItemTemplate>
                        <asp:TextBox ID="txtCeasar" Text='<%# Bind("Ceasar") %>' runat="server"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lblCeasar" Text='<%# Eval("Ceasar") %>' runat="server"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="County" SortExpression="[County]">
                    <EditItemTemplate>
                        <asp:TextBox ID="txtCounty" Text='<%# Bind("County") %>' runat="server"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lblCounty" Text='<%# Eval("County") %>' runat="server"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="ACT" DataFormatString="{0:d}" HtmlEncode="false" HeaderText="ACT" SortExpression="[ACT]" />
                <asp:BoundField DataField="Sat_Type" HeaderText="Sat" ReadOnly="True" SortExpression="[Sat_Type]" />
                <asp:HyperLinkField DataNavigateUrlFields="AgtNo5" DataNavigateUrlFormatString="http://agent.allstate.com/{0}/welcome/"
                    HeaderText="Web" Target="_blank" Text="Web" />
                <asp:CommandField HeaderText="Edit" InsertVisible="False" ShowEditButton="True" ShowHeader="True"
                    Visible="False" />
            </Columns>
		</asp:GridView>

Open in new window

SeTechAsked:
Who is Participating?
 
SeTechConnect With a Mentor Author Commented:
What I ended up doing was using a SQL Server built-in method as such :
dbo.Proper(FName) AS FName
0
 
Bob LearnedCommented:
How does the page get rendered in HTML (View Source)?

I would think that if you applied the 'salesdirgrid' CSS class to RowStyle that it might help.

Bob
0
 
SeTechAuthor Commented:
I just checked, and it gets rendered as an HTML table.

I also tried applying the CSS 'salesdirgrid' drectly to the row, but though by the text size I could tell it had correctly applied to the rows, the text still isn't Proper Cased.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Bob LearnedCommented:
I hadn't use that text-transform style before, so I worked up a little test, and it worked fine:

        <table>
            <tr>
                <td class="class">this is a test of the radio broadcast system</td>
            </tr>
        </table>

This only worked is the class name was 'class'.  It wouldn't apply any styles, if I renamed the class to anything else (including the blue color), even though the designer showed it correctly.

Bob
0
 
SeTechAuthor Commented:
Hrmm, I gave that a try, but it still is showing most of my fields in ALL CAPS, even with the CSS class named "class".

Anything else?
0
 
Bob LearnedCommented:
Did you try it in a sandbox temporary, working project?  My sandbox test project is a Web Site model (no .csproj file), and not a Web Application model (.csproj file), if that makes any difference.

Bob
0
 
SeTechAuthor Commented:
No, I just tried to basically throw it to the wolves, so to speak.

This isn't an urgent requirement, but it looks kinda tacky for everything to be in ALL CAPS, can anything be done?
0
 
Bob LearnedConnect With a Mentor Commented:
You might be able to use a casing method applied to the datasource:

System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(text)

Bob
0
All Courses

From novice to tech pro — start learning today.