Home > ASP.Net > Change FontSize with Gridview According to Condition

Change FontSize with Gridview According to Condition


Hi all,

Try this example to Change FontSize with Gridview According to Condition

add this CSS Style in your page

    <style type="text/css">   
    .Small   
    {       
    font-size: small;   
    }   
    .Large   
    {       
    font-size: large;   
    }
    </style>

In Gridview ItemTemplate

<asp:TemplateField HeaderText="Description" SortExpression="Description">
           <ItemTemplate>
               <asp:Label ID="Label1" runat="server" Text='<%# Bind("Description") %>' CssClass='<%# (Convert.ToString(Eval("Description")).Length > 30)? "Small": "Large"%>'></asp:Label>
           </ItemTemplate>
</asp:TemplateField>

and there is another way to do the same

<asp:TemplateField HeaderText="Description" SortExpression="Description">
          <ItemTemplate>
             <asp:Label ID="Label1" runat="server" Text='<%# Bind("Description") %>' Font-Size='<%# (Eval("Description").ToString().Length > 30) ? FontUnit.XSmall : FontUnit.Small %>'></asp:Label>
          </ItemTemplate>
</asp:TemplateField>

Hope this helps

Good Luck

Advertisements
Categories: ASP.Net
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: