473,545 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hyperlink column in a GridView

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?
Jun 14 '07 #1
4 4116
Hi,

One approach is create a column for hyperlink and in HyperLink attribute of
Enable call the function which will return true or false based on if detail
records are there are not.

It will be something like:

<asp:GridView >
..
..
..
<columns>
<asp:HyperLin k runat="server" Enabled='<% IsDetailsRecord %>'
</asp:GridView>

Code Behind Page

protected bool IsDetailsRecord ()
{

//your logic
return;
}
"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?
Jun 14 '07 #2
Hi Raj

Thanks for your reply. I am afraid I need to leave now so I haven't been
able to try your suggestion.

Would your way still show the ID underlined? The requirement is that the ID
should only be underlined if the record has child data.

"Raj" wrote:
Hi,

One approach is create a column for hyperlink and in HyperLink attribute of
Enable call the function which will return true or false based on if detail
records are there are not.

It will be something like:

<asp:GridView >
.
.
.
<columns>
<asp:HyperLin k runat="server" Enabled='<% IsDetailsRecord %>'
</asp:GridView>

Code Behind Page

protected bool IsDetailsRecord ()
{

//your logic
return;
}
"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?
Jun 14 '07 #3
you can add some logic in the code behind for that.

"Amir Tohidi" <Am********@dis cussions.micros oft.comwrote in message
news:E2******** *************** ***********@mic rosoft.com...
Hi Raj

Thanks for your reply. I am afraid I need to leave now so I haven't been
able to try your suggestion.

Would your way still show the ID underlined? The requirement is that the
ID
should only be underlined if the record has child data.

"Raj" wrote:
>Hi,

One approach is create a column for hyperlink and in HyperLink attribute
of
Enable call the function which will return true or false based on if
detail
records are there are not.

It will be something like:

<asp:GridVie w>
.
.
.
<columns>
<asp:HyperLi nk runat="server" Enabled='<% IsDetailsRecord %>'
</asp:GridView>

Code Behind Page

protected bool IsDetailsRecord ()
{

//your logic
return;
}
"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?

Jun 14 '07 #4
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?
Jun 15 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3522
by: TPhelps | last post by:
I have a sample of an unbound (autogeneratecolumns is true) sortable/pagable datagrid that works. I want to change one of the columns to a hyperlink. The examples I find use a bound column. I can get this to work; however, the column header on the datagrid is not a link/sortable. What am I missing? Thanks in advance.
1
2093
by: Carlos | last post by:
Hi all, I need a field that it is both databound, and hyperlink in a gridview. That is, the value is obtained from a query, and at the same time needs to point to a new page where will be used to make another query. How can this be possible in asp .net? Thanks in advance, Carlos.
3
4157
by: Bren | last post by:
Hi All VS2005 Gridview control with vb I am populating a gridview of company staff. One of the columns is a hyperlink to a SMS texting facility I have so secrataries can text the managers etc. i.e Secratary loads the page on the intranet, finds the manager they want to contact, clicks on the "SMS" hyperlink and is taken to the SMS page...
3
3116
by: William LaMartin | last post by:
I have a gridview (with no properties set) on an aspx page which I populate from an XML file with the code below. The data in the XML file looks like this <description>National Trust for Historic Preservation</description> <URL>http://www.nthp.org/</URL> <category>Architecture</category> Can anyone tell me why the other two columns...
3
3041
by: shapper | last post by:
Hello, In my GridView I have a HyperLink Field where I set the DataNavigateUrlFormaString MyHyperLinkField.DataNavigateUrlFormatString = "~\RSS.ashx?Channel={0}&Culture=" & System.Threading.Thread.CurrentThread.CurrentCulture.ToString() I believe {0} retrieves the value of my datasource column with index 0.
1
1332
by: bbawa1 | last post by:
I have a table with two columns AppName AppLocation TestApp1 folder1 TestApp2 folder2 TestApp3 folder3 TestApp4 folder4 TestApp5 folder5
1
13827
by: Frank Milverckowitz | last post by:
Hi, I'm trying to do something common and what should be simple using the GridView "Add Columns" feature in Visual Studio 2005. All I want to do is add a Hyperlink column that will take the user to another aspx page for editing (I'm not using the built in edit feature because I have too many columns)
1
7140
by: Valli | last post by:
Hi, I need to display an hyperlink column in gridview where if the user clicks that column the page should move to the selected page. I have got help from this group & started using template field. After using this, I couldnt see a column supporting hyperlink. In the gridviews first column header, there appears an hyperlink with the first...
1
3034
by: Author | last post by:
I got into trouble with this problem. The data I am presenting in a GridView control has a column called "Website". That data comes from a stored procedure in SQL Server 2000. Most of them have valid http urls. But some of them say "None" or "Not available". In the GridView, I would like create a hyperlink for those valid http urls...
0
7478
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...
0
7410
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7923
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5343
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4960
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...
0
3466
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...
1
1901
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
1025
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
722
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...

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.