code in the webpage:
code in the CSS file
#myRedText
{
color: red;
}
.blueText
{
color: blue;
}
Sometimes it would be nice to have a “select all” feature for your grid check boxes.
This can be easily accomplished using the header template of the grid view.
ASP.net code
<asp:GridView ID="gvTagEndorsementTypes"
runat="server" AutoGenerateColumns="false" >
<Columns>
<asp:TemplateField HeaderText="Select">
<HeaderTemplate>
<asp:LinkButton ID="lbSelectEndorsements"
OnClick="ToggleEndorsements_Click" runat="server"> Select
</asp:LinkButton>
</HeaderTemplate>
<ItemTemplate >
<asp:CheckBox ID="cbSelect" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
...
protected void ToggleEndorsements_Click(object sender, EventArgs e)
{ foreach (GridViewRow erow in gvTagEndorsementTypes.Rows)
{ CheckBox echeckbox = (CheckBox)erow.FindControl("cbSelect"); //see if the checkbox is checked. if (echeckbox.Checked) { echeckbox.Checked = false; } else { echeckbox.Checked = true; }
}
}
You can use the EmptyDataTemplate in your gridviews to display a message when “no data is found”. This is an alternative to using code to check the number of rows in the gridview and show/hiding some label to indicate this. The EmptyDataTemplate goes before the column definitions.
<asp:GridView ID="gvAuthorityExemptions"
AutoGenerateColumns="false" GridLines="None"
runat="server" Width="100%">
<EmptyDataTemplate>
<asp:Label ID="lblNoData" runat="server">
No Exemptions for License/Authority
</asp:Label>
</EmptyDataTemplate>
<Columns> …
To display a date in mm/dd/yyyy format in a GridView use the following (make sure the “MM” is capitalized, because “mm” = minutes)
<asp:TemplateField HeaderText="Trip Date" >
<ItemTemplate >
<%# Server.HtmlEncode( Eval("TripDate", "{0:MM/dd/yyyy}").ToString() ) %>
</ItemTemplate>
</asp:TemplateField>