Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / June 2007

Tip: Looking for answers? Try searching our database.

Hyperlink column in a GridView

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Amir Tohidi - 14 Jun 2007 16:49 GMT
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?
Raj - 14 Jun 2007 16:56 GMT
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;
}

> Hi
>
[quoted text clipped - 10 lines]
>
> What is the best way of doing this please?
Amir Tohidi - 14 Jun 2007 17:28 GMT
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.

> Hi,
>
[quoted text clipped - 35 lines]
> >
> > What is the best way of doing this please?
Mike - 14 Jun 2007 18:21 GMT
you can add some logic in the code behind for that.

> Hi Raj
>
[quoted text clipped - 51 lines]
>> >
>> > What is the best way of doing this please?
Amir Tohidi - 15 Jun 2007 12:07 GMT
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;
       }

> Hi
>
[quoted text clipped - 10 lines]
>
> What is the best way of doing this please?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.