I do this by applying a style on the DataBinding
event of one of my controls in a template. Example:
<asp:GridView ID="grdYourGrid" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="SomeTitle">
<ItemTemplate>
<asp:HyperLink ID="hrefYourLink" runat="server"
NavigateUrl="Somepage.aspx?id={0}"
OnDataBinding="hrefYourLink_DataBinding"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Then implement the OnDataBinding
event:
protected void hrefYourLink_DataBinding(object sender, System.EventArgs e)
{
HyperLink link = (HyperLink)(sender);
GridViewRow row = (GridViewRow)(link.Parent.Parent);
if ((bool)(Eval("IsObsolete"))
{
row.CssClass = "StrikeThroughStyle";
}
link.Text = HttpUtility.HtmlEncode(((int)(Eval("ID"))).ToString());
link.NavigateUrl = string.Format(link.NavigateUrl, Eval("ID").ToString());
}
This is just an quick example with a column with a link that gets modified based on the databinding as well but you should be able to get the gist of if an tweak it to suit your needs. I like doing it on the databinding because I do no binding inline in my aspx code.