473,606 Members | 2,101 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:hyperlinkc olumn headertext="Que stion" SortExpression= "QDescripti on"
datatextfield=" QDescription"
datanavigateurl formatstring="A nswers.aspx?QID ={0}"
datanavigateurl field="QID">
</asp:hyperlinkco lumn>
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 2586
One option is to use template-based columns. Eg:

<asp:DataGrid.. .>
...
<ItemTemplate >
<%# ShowQDescriptio n (DataBinder.Eva l(Container.Dat aItem, "QID"),
DataBinder.Eval (Container.Data Item, "QDescription") ) %>
</ItemTemplate>
...
</asp:DataGrid>

In your code-behind, define a function named ShowQDescriptio n() as

protected string ShowQDescriptio n (int qID, string qDesc)
{
string linkTag = null;
if (qID == 1 || qID == 4 || qID == 5 || qID == 6)
{
linkTag = "<a href='answers.a spx?QID=" + ownerID.ToStrin g() + "'>" +
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:HyperLinkC olumn Enabled=<%#
IsEnabled(DataB inder.Eval(Cont ainer.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***@discussi ons.microsoft.c om> wrote in message
news:AF******** *************** ***********@mic rosoft.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:hyperlinkc olumn headertext="Que stion" SortExpression= "QDescripti on"
datatextfield=" QDescription"
datanavigateurl formatstring="A nswers.aspx?QID ={0}"
datanavigateurl field="QID">
</asp:hyperlinkco lumn>
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 ShowQDescriptio n).
It's working fine.

Initially I got syntax errors.
I need to put ".Tostring( )"
ShowQDescriptio n (DataBinder.Eva l(Container.Dat aItem, "QID").ToString (),
DataBinder.Eval (Container.Data Item, "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 >
<%# ShowQDescriptio n (DataBinder.Eva l(Container.Dat aItem, "QID"),
DataBinder.Eval (Container.Data Item, "QDescription") ) %>
</ItemTemplate>
...
</asp:DataGrid>

In your code-behind, define a function named ShowQDescriptio n() as

protected string ShowQDescriptio n (int qID, string qDesc)
{
string linkTag = null;
if (qID == 1 || qID == 4 || qID == 5 || qID == 6)
{
linkTag = "<a href='answers.a spx?QID=" + ownerID.ToStrin g() + "'>" +
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:HyperLinkC olumn Enabled=<%#
IsEnabled(DataB inder.Eval(Cont ainer.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***@discussi ons.microsoft.c om> wrote in message
news:AF******** *************** ***********@mic rosoft.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:hyperlinkc olumn headertext="Que stion" SortExpression= "QDescripti on"
datatextfield=" QDescription"
datanavigateurl formatstring="A nswers.aspx?QID ={0}"
datanavigateurl field="QID">
</asp:hyperlinkco lumn>
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 ShowQDescriptio n method was declared to accept
string parameters whereas the DataBinder.Eval () passed other type of data
from the data source.
"Kumar" <Ku***@discussi ons.microsoft.c om> wrote in message
news:39******** *************** ***********@mic rosoft.com...
Hi siva,

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

Initially I got syntax errors.
I need to put ".Tostring( )"
ShowQDescriptio n (DataBinder.Eva l(Container.Dat aItem, "QID").ToString (),
DataBinder.Eval (Container.Data Item, "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 >
<%# ShowQDescriptio n (DataBinder.Eva l(Container.Dat aItem, "QID"),
DataBinder.Eval (Container.Data Item, "QDescription") ) %>
</ItemTemplate>
...
</asp:DataGrid>

In your code-behind, define a function named ShowQDescriptio n() as

protected string ShowQDescriptio n (int qID, string qDesc)
{
string linkTag = null;
if (qID == 1 || qID == 4 || qID == 5 || qID == 6)
{
linkTag = "<a href='answers.a spx?QID=" + ownerID.ToStrin g() + "'>"
+
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:HyperLinkC olumn Enabled=<%#
IsEnabled(DataB inder.Eval(Cont ainer.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***@discussi ons.microsoft.c om> wrote in message
news:AF******** *************** ***********@mic rosoft.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:hyperlinkc olumn headertext="Que stion" SortExpression= "QDescripti on"
datatextfield=" QDescription"
datanavigateurl formatstring="A nswers.aspx?QID ={0}"
datanavigateurl field="QID">
</asp:hyperlinkco lumn>
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
449
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 "..If ...Then..) within the TD it simply displays that as text. I am not sure how to code this conditon? What I am trying to accomplish is something like the following. I want to test the "status" field for the condition. <td> If <%#...
3
1774
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 tried using CSS but that doesn't affect what is going on in my datagrid. This is what I have so far for formatting in my datagrid... Sub ItemBound(ByVal sender As Object, ByVal e as DataGridItemEventArgs) If e.Item.ItemType = ListItemType.Item Or...
3
15401
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 createTable() Dim tbcontacts As DataTable = New DataTable("contacts") tbcontacts.Columns.Add(" ", System.Type.GetType("System.String"))
2
4281
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 just Qdescription with out hyperlink. <asp:hyperlinkcolumn headertext="Question" SortExpression="QDescription"
19
3476
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 to here as page_2). I need to cache the value of the link's text (hyperlink.text property) so that I can use it in the page_load event of page_2. I've thought of using a hidden field and then calling Request.Form("hdnClickedLinkText") in the...
0
8009
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8432
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8078
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5456
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3919
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3964
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2442
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1548
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1285
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.