Solved

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

Posted on 2008-10-29
8
745 Views
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.
0
Comment
Question by:bolenka
[X]
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
8 Comments
 
LVL 22

Expert Comment

by:prairiedog
ID: 22842326
1). Are you using the solution that I proposed in your related question: http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_23844259.html
3). Where do you want to add this: '18/25 questions completed'?
0
 

Author Comment

by:bolenka
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 story...you 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 hurry...so 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


or


25/25 Questions Completed
Compete Evaluation | Return to List


or
 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.

0
 
LVL 22

Expert Comment

by:prairiedog
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.
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:bolenka
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.
0
 
LVL 22

Expert Comment

by:prairiedog
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
    Else
         hl.Visible = False
    End If
End Sub
0
 
LVL 22

Accepted Solution

by:
prairiedog earned 500 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.
0
 

Author Comment

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

Author Closing Comment

by:bolenka
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.
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

623 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