473,508 Members | 2,110 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 4112
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:HyperLink 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:HyperLink 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********@discussions.microsoft.comwrote in message
news:E2**********************************@microsof t.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:GridView>
.
.
.
<columns>
<asp:HyperLink 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:TemplateField HeaderText="Transaction" SortExpression="FunctionCategory">
<ItemStyle Width="20%" />
<ItemTemplate>
<%# this.GetTransactionColumnHTML( (int)Eval("ID"),
(string)Eval("FunctionCategory"), (int)Eval("DetailsCount") )%>
</ItemTemplate>
</asp:TemplateField>

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">Primary key of of the master audit record being
rendered</param>
/// <param name="functionCategory">The transaction type e.g.
Login</param>
/// <param name="detailsCount">The number of details records
associated witht the master audit record</param>
/// <returns>HTML fragement</returns>
public string GetTransactionColumnHTML(int pk, string
functionCategory, int detailsCount)
{
string s = string.Empty;

if (detailsCount 0)
{
// Master record has details records, so return a hyperlink
to the AuditDetails.aspx
s = "<a href='AuditDetails.aspx?MasterID=" +
Convert.ToString(pk) + "'>" + functionCategory + "</a>";
}
else
{
// Master record doesn't have any children so just return a
label.
s = "<label>" + functionCategory + "</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
3517
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...
1
2092
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...
3
4153
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...
3
3111
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...
3
3039
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=" &...
1
1331
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...
1
7135
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...
1
3030
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...
0
7225
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
7326
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,...
1
7046
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...
0
7498
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...
0
5629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4707
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...
0
3195
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...
0
1558
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 ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.