10/08/2021

Conditional Formatting in Asp .Net Web Form Gridview

 

<asp:TemplateField HeaderText="Status" SortExpression="Status">
     <EditItemTemplate>
        <asp:Label ID="lblStatus" runat="server" Text='<%# Eval("Status") %>'></asp:Label>
     </EditItemTemplate>
     <ItemTemplate>
        <asp:Label ID="lblStatus" runat="server" Text='<%# Bind("Status") %>' ForeColor='<%# ((string)Eval("Status")).ToLower().Equals("open") ? System.Drawing.Color.Green : System.Drawing.Color.Red %>'></asp:Label>
     </ItemTemplate>
 </asp:TemplateField>