Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How do I conditionally add dynamic hyperlinks to the Formview pager template using ASP.NET vb?

Posted on 2008-10-29
Medium Priority
Last Modified: 2012-06-27
I am using a Formview with Paging Enabled. My client wants to show some Hyperlinks based on some specific circumstances. Each page represents a quiz question. Here are the requirements for creating the links conditionally (please keep in mind that my Formview is in a Content Page:

1)Once all 25 quizes have been completed (completed meaning the individual record for each quiz question is set to Completed = 'true'), the client wants a hyperlink that takes you to a page to "Complete Evaluation". This Evaluation Link can only be shown if the user has not  yet entered an evaluation record into the evaluation table.
2) The evaluation Link can only be shown once the person completes the last quiz question( I guess this would be on postback after completing the last record.
3)I have to show a count of Completed questions like '18/25 questions completed'

In what event do I create these hyperlinks?
How do I add them to the PagerTemplate dynamically?

Any info you could give would be greatly appreciated.
Question by:bolenka
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
LVL 22

Expert Comment

ID: 22842326
1). Are you using the solution that I proposed in your related question:
3). Where do you want to add this: '18/25 questions completed'?

Author Comment

ID: 22843359
actually, I am not sure if I will have time to implement your solution overall with out a lot of css changes (since I already have a certain css implemented with master pages), so I will try to go back to institute that after I have a chance to really analyze how it looks, but either way, I still need to get the paging to work. I actually explained the problem that you and I had discussed to the client yesterday, and he wants to try to implement it the way it is for right now, which means, I am just going to work around the recordset problem for now(he mentioned something about using the page_unload to update the record to complete which still would remove the record from the recordset, but hopefully, I will still be able to see all of the data before it is removed). Anyway, I havent had time to look into it, but my client did research and found that maybe we could use the page_unload to set the completed = true ...anyway, that is another know they just want a quick fix, so I am temporarily going to get rid of the readonly and edit modes, and just use edit mode. this doesnt solve my problem of taking the record out of the recordset...anyway regardless of the solution I use, I still have to get the pager links in the templates correct....for now, I will have to come back to implement the css issue because they just don't want to do it right now...but that doesnt mean your hard work was for nothing!!! I learned a great deal from your explanation, and i plan to come back to it. I am rambling due to being in a sorry:)

To answer your other question:
For now, I think I just want the 18/25 completed records to show up right above the others like this:

18/30 Questions Completed
Go To Next Question | Return to LIst


25/25 Questions Completed
Compete Evaluation | Return to List

 if Evaluation has previously been completed

25/25 Question Completed
Print Certificate | Return to List

I think the footer (pagertemplate) would be centered? Don't you think? What do you think? THank you so much.

LVL 22

Expert Comment

ID: 22845135
Hi bolenka,
The reason I asked you if you are using my solution is because if you are, then you need to go a different route to implement the new requirements (you may need to get all the reuirements altogether; the requirement change in the coding phase is a real pain).
Anyway, your client misunderstood Page_Unload event. This event fires right before the page is rendered into the client browser. Do a search on "ASP.NET Page Life Cycle" and you will understand more.
If you want to do batch update, then you will probablly need to handle the update process manually, instead of using SqlDataSource's update process.
Seems to me, there are still some unknowns and it is hard for me to give you a solid suggestion based on my knowledge. Maybe other experts have a different opion.
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments


Author Comment

ID: 22849077
I understand what you mean prairiedog. This project has been really frustrating and they have been chaning the requirements a lot, but I kind of don't have a choice. I did everything I could to avoid it, but it just seems to not be my day if you will.

How about this? I can make my question easier to understand since I was blabbering on before and probably confused you:)

What is the syntax for dynamically creating conditional Navigation links in the pager template for formview?
 In other words, If I want to add some links to the pager template on postback, how would I do that? I guess that would be my question for now. I just want to dynamically add some links to the pager template (as shown above). Dont worry about the paging. What event do I use to create these links conditionally? And what would the syntax be? Does that make sense? Sorry for the confusion. Thanks again.
LVL 22

Expert Comment

ID: 22849962
Generally speaking, here is how you create a HyperLink control in FormView's Pager (I assume the pager is at the bottom) and retrieve it later on:
1. Create a HyperLink control in FormView's PagerTemplate field.
2. In code behind, you will need to use FormView's DataBound event handler:

Private Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.DataBound
       Dim pagerRow As FormViewRow = Me.FormView1.BottomPagerRow
        Dim hl As HyperLink = CType(pagerRow.Cells(0).FindControl("HyperLink1"), HyperLink)
      'here you check if the user finished all questions, then display the hyperlink,
     ' otherwise, hide the hyperlink
     If (conditionIsTrue) Then
          hl.Visible = True
         hl.Visible = False
    End If
End Sub
LVL 22

Accepted Solution

prairiedog earned 2000 total points
ID: 22849985
So to sum up, you do not dynamically create the links. You create it in PaterTemplate, then toggle it on or off in code-behind based on the condition.

Author Comment

ID: 22850466
Ok, awesome. I will check it out real quick. thanks!

Author Closing Comment

ID: 31511534
sorry prarie dog...busy week/weekend...deadlines, kids, tricks or treats and election...anyway...sorry it took so long. You have helped me greatly. getting ready to post another in fact:) thanks again.

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question