Figured it out. I needed to add the Checkbox to the item template to make sure it shows up after saving/editing. Then i needed to deal with the Null in C#
ASP.NET markup:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
GridView1_RowUpdating="true" DataKeyNames="ID" OnRowUpdating="Page_Load"
BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid"
BorderWidth="3px" CellPadding="4" CellSpacing="2" ForeColor="Black"
OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="Verify Info Prod & Maturity Level" SortExpression="IPMaturity">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("IPMaturity", "{0:MM/dd/yyyy}") %>' Width="75"></asp:TextBox>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" Text="Complete" Enabled="true"
Checked='<%# Bind ("CheckBox1") %>'></asp:CheckBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblIPMat" runat="server" Text='<%# Eval("IPMaturity", "{0:MM/dd/yyyy}") %>' Width="75"></asp:Label>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind ("CheckBox1") %>'/>
</ItemTemplate>
<HeaderStyle CssClass="verticaltext" Height="140px" Width="88px" HorizontalAlign="Center" VerticalAlign="Bottom" />
</asp:TemplateField>
C# Code Behind
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (((CheckBox)e.Row.FindControl("CheckBox1")) != null && ((CheckBox)e.Row.FindControl("CheckBox1")).Checked)
{
e.Row.Cells[4].BackColor = System.Drawing.Color.Black;
e.Row.Cells[4].ForeColor = System.Drawing.Color.White;
}
else
{
string ipMaturity = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "IPMaturity"));
DateTime? date1 = !string.IsNullOrEmpty(ipMaturity) ? Convert.ToDateTime(ipMaturity) : (DateTime?)null;
if (date1.HasValue && date1 >= DateTime.Now)
e.Row.Cells[4].BackColor = System.Drawing.Color.White;
if (date1.HasValue && date1 < DateTime.Now)
e.Row.Cells[4].BackColor = System.Drawing.Color.Red;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…