I have a templated column in a datagrid that I wish to change to a different color based on a value in one of the fields. I put in a label control to try to get a handle on the field value at runtime but it always returns a blank string ("") instead of the value, which I can see in the datagrid after it renders
Here is my html:
And here is what I have in the ItemDataBound event
What am i doing wrong here?
When I view the source of the rendered page my label id has been corrupted and looks like this now
<span id="MyGrid__ctl16_lblCurrentStatus">Current
Here is my html:
Code:
<asp:TemplateColumn HeaderText="Status">
<ItemTemplate>
<asp:Label id="lblCurrentStatus" Runat="server">
<%# DataBinder.Eval(Container.DataItem, "current_status") %>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList runat="server" ID="Dropdownlist1"/>
</EditItemTemplate>
</asp:TemplateColumn>
And here is what I have in the ItemDataBound event
Code:
private void SbeGrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
try
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Label lblStat = (Label)e.Item.FindControl("lblCurrentStatus");
string frylock = lblStat.Text;
System.Diagnostics.Debug.WriteLine("val is " + frylock);
if (frylock == "Current")
{
lblStat.ForeColor = System.Drawing.Color.Blue;
e.Item.BackColor = System.Drawing.Color.Aqua;
}
}
What am i doing wrong here?
When I view the source of the rendered page my label id has been corrupted and looks like this now
<span id="MyGrid__ctl16_lblCurrentStatus">Current