473,395 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

conditional hyperlink in datagrid

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
3 2570
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: Wayne Wengert | last post by:
In a Datagrid I have a field (<td>) in which I want to display a link if a database field is still Null but I want to display a blank (&nbsp;) if that DB field has a value. If I try to put the...
3
by: chuckdfoster | last post by:
I have a hyperlink column in my datagrid. I want my hyperlink to be green or red (depending on in/out status) no matter if the link has been visited or not. How can I accomplish this? I have...
3
by: Tim::.. | last post by:
I currently have the following datagrid but want to turn the name and email column into a hyperlink in the codebehind! Can someone please tell me how I achieve this! Thanks Private Sub...
2
by: Kumar | last post by:
Hi Folks, I have a question regarding conditional hyperlink in datagrid of asp.net ,c# application I want to display Hyperlink if my QID values in (1,4,5,6) other wise i want to display...
19
by: Joe | last post by:
I have an aspx page (referred to here as page_1) with a datagrid whose first column contains hyperlinks. When a user clicks one of these hyperlinks, he will navigate to another aspx page (referred...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.