By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,837 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,837 IT Pros & Developers. It's quick & easy.

conditional hyperlink in datagrid

P: n/a
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


Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

Nov 17 '05 #2

P: n/a
Hi siva,

Thank you for your help.
I did exactly what you told me.
(Write a separate function ShowQDescription).
It's working fine.

Initially I got syntax errors.
I need to put ".Tostring()"
ShowQDescription (DataBinder.Eval(Container.DataItem, "QID").ToString(),
DataBinder.Eval(Container.DataItem, "QDescription").ToString())

To find this syntax problem it took me 30 mts.
How do you debug this kind of errors in html page using visual studio.net
2003?
I tried for it with out luck.

Anyway, Finally my conditional hyperlink is working perfectly.
Thanks again for all your help.
Kumar

"Siva M" wrote:
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


Nov 17 '05 #3

P: n/a
This is probably because ShowQDescription method was declared to accept
string parameters whereas the DataBinder.Eval() passed other type of data
from the data source.
"Kumar" <Ku***@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
Hi siva,

Thank you for your help.
I did exactly what you told me.
(Write a separate function ShowQDescription).
It's working fine.

Initially I got syntax errors.
I need to put ".Tostring()"
ShowQDescription (DataBinder.Eval(Container.DataItem, "QID").ToString(),
DataBinder.Eval(Container.DataItem, "QDescription").ToString())

To find this syntax problem it took me 30 mts.
How do you debug this kind of errors in html page using visual studio.net
2003?
I tried for it with out luck.

Anyway, Finally my conditional hyperlink is working perfectly.
Thanks again for all your help.
Kumar

"Siva M" wrote:
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


Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.