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:TemplateFi eld HeaderText="Tra nsaction" SortExpression= "FunctionCatego ry">
<ItemStyle Width="20%" />
<ItemTemplate >
<%# this.GetTransac tionColumnHTML( (int)Eval("ID") ,
(string)Eval("F unctionCategory "), (int)Eval("Deta ilsCount") )%>
</ItemTemplate>
</asp:TemplateFie ld>
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">Prima ry key of of the master audit record being
rendered</param>
/// <param name="functionC ategory">The transaction type e.g.
Login</param>
/// <param name="detailsCo unt">The number of details records
associated witht the master audit record</param>
/// <returns>HTML fragement</returns>
public string GetTransactionC olumnHTML(int pk, string
functionCategor y, int detailsCount)
{
string s = string.Empty;
if (detailsCount 0)
{
// Master record has details records, so return a hyperlink
to the AuditDetails.as px
s = "<a href='AuditDeta ils.aspx?Master ID=" +
Convert.ToStrin g(pk) + "'>" + functionCategor y + "</a>";
}
else
{
// Master record doesn't have any children so just return a
label.
s = "<label>" + functionCategor y + "</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?