One option is to use template-based columns. Eg:
<asp:DataGrid...>
...
<ItemTemplate>
<%# ShowQDescription (DataBinder.Eval(Container.DataItem, "QID"),
DataBinder.Eval(Container.DataItem, "QDescription")) %>
</ItemTemplate>
...
</asp:DataGrid>
In your code-behind, define a function named ShowQDescription() as
protected string ShowQDescription (int qID, string qDesc)
{
string linkTag = null;
if (qID == 1 || qID == 4 || qID == 5 || qID == 6)
{
linkTag = "<a href='answers.aspx?QID=" + ownerID.ToString() + "'>" +
qDesc + "</a>";
}
else
{
linkTag = qDesc;
}
return linkTag;
}
Other option is to have the hyperlinkcoulmn as you have now, but enable or
disable it based on the QID. Use the above-shown technique to determine the
value for Enabled attribute of the hyperlinkcolumn
<asp:HyperLinkColumn Enabled=<%#
IsEnabled(DataBinder.Eval(Container.DataItem, "QID")) %> />
IsEnabled will return True of False based on the QID passed to it.
Yet another option is to handle ItemDataBound event of the grid and handle
enabling hyperlink in the event handler.
Hope this helps.
-Siva
"Kumar" <Ku***@discussions.microsoft.com> wrote in message
news:AF**********************************@microsof t.com...
Hi Folks,
I have a question regarding conditional hyperlink in datagrid.
I want to display Hyperlink if my QID values in (1,4,5,6) other wise i
want to display just Qdescription with out hyperlink.
<asp:hyperlinkcolumn headertext="Question" SortExpression="QDescription"
datatextfield="QDescription"
datanavigateurlformatstring="Answers.aspx?QID={0}"
datanavigateurlfield="QID">
</asp:hyperlinkcolumn>
How can I achieve that kind of functionality?
I looked at the following URL
http://www.dotnet247.com/247referenc...45/226672.aspx
But I didn't get solution for my problem.
Any kind of help is greatly appreciated.
Thanking you
Kumar