ASP.NET Change Text and Color in Gridview cell in a Template Field

DeMATRIX

New Member
I have Gridview in ASP.net that displays data. Depending on the data it changes color and text depending on the value of the cell.This works fine when a column is NOT a template field.\[code\] //WORKS WHEN IS NOT A TEMPLATE FIELD if (e.Row.RowType == DataControlRowType.DataRow) { if (e.Row.Cells[2].Text == "1") { e.Row.Cells[2].Text = "IN"; e.Row.Cells[2].BackColor = Color.Blue; e.Row.Cells[2].ForeColor = Color.White; } }\[/code\]Now I converted the Column in to a Template field and nothing works.\[code\] //DOEST NOT WORK WHEN IS a TEMPLATE FIELD if (e.Row.RowType == DataControlRowType.DataRow) { if (e.Row.Cells[2].Text == "1") { e.Row.Cells[2].Text = "IN"; e.Row.Cells[2].BackColor = Color.Blue; e.Row.Cells[2].ForeColor = Color.White; } }\[/code\]I GOT THE COLOR WORKING, but now I need to change the Text to the following. IF statusID == 1 then display IN, else if statusID == 2 then display OUT\[code\]<asp:TemplateField HeaderText="StatusID" SortExpression="StatusID"> <EditItemTemplate> <asp:DropDownList ID="DropDownList1" runat="server" SelectedValue = 'http://stackoverflow.com/questions/15907217/<%# Bind("StatusID") %>'> <asp:ListItem Value="http://stackoverflow.com/questions/15907217/1">IN</asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15907217/2">OUT</asp:ListItem> </asp:DropDownList> </EditItemTemplate> <ItemTemplate> <asp:Label ID="lblStatus" runat="server" Text='<%# Bind("StatusID") %>' ForeColor='<%# Convert.ToString(Eval("StatusID")) == "1" ? System.Drawing.Color.Green: Convert.ToString(Eval("StatusID")) == "2" ? System.Drawing.Color.Red: System.Drawing.Color.Purple%>'></asp:Label> </ItemTemplate> </asp:TemplateField>\[/code\]Any of you know how to solve this issue. Thanks in advance.
 
Top