Hi
This is how I fixed the problem:
In the aspx, I added an ItemTemplate column that calls my code behind
passing in important property values of the underlyinf record that is being
bound to (such as the primary key which is called ID):
<asp:TemplateField HeaderText="Transaction" SortExpression="FunctionCategory">
<ItemStyle Width="20%" />
<ItemTemplate>
<%# this.GetTransactionColumnHTML( (int)Eval("ID"),
(string)Eval("FunctionCategory"), (int)Eval("DetailsCount") )%>
</ItemTemplate>
</asp:TemplateField>
The code behind then does:
/// <summary>
/// Returns an HTML fragment to be used for the Transaction column
in the grid.
/// If the master record has details records an anchor with a link
to the details page is returned;
/// otherwise, a label with the transaction name is returned.
/// </summary>
/// <param name="pk">Primary key of of the master audit record being
rendered</param>
/// <param name="functionCategory">The transaction type e.g.
Login</param>
/// <param name="detailsCount">The number of details records
associated witht the master audit record</param>
/// <returns>HTML fragement</returns>
public string GetTransactionColumnHTML(int pk, string
functionCategory, int detailsCount)
{
string s = string.Empty;
if (detailsCount 0)
{
// Master record has details records, so return a hyperlink
to the AuditDetails.aspx
s = "<a href='AuditDetails.aspx?MasterID=" +
Convert.ToString(pk) + "'>" + functionCategory + "</a>";
}
else
{
// Master record doesn't have any children so just return a
label.
s = "<label>" + functionCategory + "</label>";
}
return s;
}
"Amir Tohidi" wrote:
Hi
I have a GridView that is displaying master records. Some of these records
have child records.
I would like to a column to my master GridView such that for each master
record that has detail records, it displays a hyperlink that then takes the
user to the details page. If a master record doesn't have any children, I
just want it to display its ID with no hyperlink.
In a nutshell: the cell must only be clickable if there are detail records
associated with that row.
What is the best way of doing this please?