Put results of a Function into HTML code

H

Henry Jones

In ASP.NET 1.1, I have a Datagrid and I have the following column:

<asp:TemplateColumn HeaderText="ID" ItemStyle-HorizontalAlign="Center"
ItemStyle-BackColor="0066cc">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem,"title_id") %>
</ItemTemplate>
</asp:TemplateColumn>


Would it be possible to call the following function:
' ********************************************************************
Function Highlight(ByVal ytdSales As Integer) As String

If ytdSales > 10000 Then
Return "#0066cc"
Else
Return "#0033aa"
End If

End Function
' ********************************************************************

and replace the value on the TemplateColumn Header for the backcolor?

How could I do this in code? I don't understand.

Thanks,

Henry
 
K

Kasumo Morris

Henry,

You could iterate through the DataGrid items collection and set the
BackColor
...
grdListing.DataBind();
foreach(DataGridItem item in grdListing.Items)
{
int ytdSales = int.Parse(item.Cells[0].Text);
item.BackColor = Color.FromName(Highlight(ytdSales));
}
...

Hope this helps
Kasumo.
 
H

Henry Jones

Thanks for reply and I'll give your code a try, but I would like to find out
if I can do what I originally requested. Is there a way replace the code in
the TemplateColumnHeader by calling a function and if so, how can I do it?

Thanks,

Gary

Kasumo Morris said:
Henry,

You could iterate through the DataGrid items collection and set the
BackColor
...
grdListing.DataBind();
foreach(DataGridItem item in grdListing.Items)
{
int ytdSales = int.Parse(item.Cells[0].Text);
item.BackColor = Color.FromName(Highlight(ytdSales));
}
...

Hope this helps
Kasumo.

Henry Jones said:
In ASP.NET 1.1, I have a Datagrid and I have the following column:

<asp:TemplateColumn HeaderText="ID" ItemStyle-HorizontalAlign="Center"
ItemStyle-BackColor="0066cc">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem,"title_id") %>
</ItemTemplate>
</asp:TemplateColumn>


Would it be possible to call the following function:
' ********************************************************************
Function Highlight(ByVal ytdSales As Integer) As String

If ytdSales > 10000 Then
Return "#0066cc"
Else
Return "#0033aa"
End If

End Function
' ********************************************************************

and replace the value on the TemplateColumn Header for the backcolor?

How could I do this in code? I don't understand.

Thanks,

Henry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top