Hi everybody !
I have a little repeater/hyperlink issue I'm not sure how to solve.
I use a repeater to list subjects available at a specific school.
The datasource of this repeater is a dataset filled with info from a
SQL Server database.
All the subjects are displayed as hyperlinks, and when a user clicks a
subject, it opens up a new browser with the website specific to that
subject (ie the specific department website).
Everything is working just fine except if the URL field in the database
table is 'NULL'. then the new browser will just display the "page
cannot be displayed" message, which is pretty obvious.
What I want to do is to make a check if the specific item in the
dataset is 'null' and if so I want the user to be redirected to my
global "message page" just passing a querystring saying, "sorry, no
available url for the moment", or something like that.
I think I should use the ItemDataBound event but I'm not sure how to do
it. I've tried a few options but I can't get it to work.
Any help would be highly appreciated !
Thanks a lot !
I include the repeater code below just in case...
In the code behind I just set the datasource of the repeater and bind
it. Nothing else is going on there...
------------------------------*----------------------------
<asp:repeater id="rptSubjects" runat="server">
<ItemTemplate>
<table>
<tr>
<td>
<asp:HyperLink NavigateUrl='<%# "http://" &
Container.DataItem("Dep_Websit*eURL") %>' text='<%#
Container.DataItem("SubjectNam*e") %>' Runat="server" Target="_blank"
ID="Hyperlink1" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:repeater>
------------------------------*----------------------------- 8 3148
Check out: http://openmymind.net/index.aspx?documentId=8
You are right about the ItemDataBound (as one of two solutions, the better
one!).
Karl
--
MY ASP.Net tutorials http://www.openmymind.net/ - New and Improved (yes, the popup is annoying) http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
<fr*******@hotmail.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
Hi everybody !
I have a little repeater/hyperlink issue I'm not sure how to solve.
I use a repeater to list subjects available at a specific school.
The datasource of this repeater is a dataset filled with info from a
SQL Server database.
All the subjects are displayed as hyperlinks, and when a user clicks a
subject, it opens up a new browser with the website specific to that
subject (ie the specific department website).
Everything is working just fine except if the URL field in the database
table is 'NULL'. then the new browser will just display the "page
cannot be displayed" message, which is pretty obvious.
What I want to do is to make a check if the specific item in the
dataset is 'null' and if so I want the user to be redirected to my
global "message page" just passing a querystring saying, "sorry, no
available url for the moment", or something like that.
I think I should use the ItemDataBound event but I'm not sure how to do
it. I've tried a few options but I can't get it to work.
Any help would be highly appreciated !
Thanks a lot !
I include the repeater code below just in case...
In the code behind I just set the datasource of the repeater and bind
it. Nothing else is going on there...
------------------------------*----------------------------
<asp:repeater id="rptSubjects" runat="server">
<ItemTemplate>
<table>
<tr>
<td>
<asp:HyperLink NavigateUrl='<%# "http://" &
Container.DataItem("Dep_Websit*eURL") %>' text='<%#
Container.DataItem("SubjectNam*e") %>' Runat="server" Target="_blank"
ID="Hyperlink1" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:repeater>
------------------------------*-----------------------------
You could use an iif statement (Assuming VB) e.g
iif(container.dataitem("Dep_WebsiteURL") is dbnull.value,
"/messagepage.aspx?message=.....", container.dataitem("Dep_WebsiteURL"))
or you could use the same technique to enable/disable the link or change the
link text... jd
"fr*******@hotmail.com" wrote: Hi everybody !
I have a little repeater/hyperlink issue I'm not sure how to solve. I use a repeater to list subjects available at a specific school. The datasource of this repeater is a dataset filled with info from a SQL Server database. All the subjects are displayed as hyperlinks, and when a user clicks a subject, it opens up a new browser with the website specific to that subject (ie the specific department website).
Everything is working just fine except if the URL field in the database
table is 'NULL'. then the new browser will just display the "page cannot be displayed" message, which is pretty obvious.
What I want to do is to make a check if the specific item in the dataset is 'null' and if so I want the user to be redirected to my global "message page" just passing a querystring saying, "sorry, no available url for the moment", or something like that.
I think I should use the ItemDataBound event but I'm not sure how to do it. I've tried a few options but I can't get it to work. Any help would be highly appreciated !
Thanks a lot !
I include the repeater code below just in case... In the code behind I just set the datasource of the repeater and bind it. Nothing else is going on there...
------------------------------Â*---------------------------- <asp:repeater id="rptSubjects" runat="server"> <ItemTemplate> <table> <tr> <td> <asp:HyperLink NavigateUrl='<%# "http://" & Container.DataItem("Dep_WebsitÂ*eURL") %>' text='<%# Container.DataItem("SubjectNamÂ*e") %>' Runat="server" Target="_blank" ID="Hyperlink1" /> </td> </tr> </table> </ItemTemplate> </asp:repeater> ------------------------------Â*-----------------------------
Hi ! Thanks for the help so far !
I'm getting a little bit closer to solve thism, but I'm not there yet.
Could someone please help me with the code in the ItemDataBound event.
What I want is something like this, but in proper vb code off course...
Private Sub rptSubjects_ItemDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles
rptSubjects.ItemDataBound
if The databound Item, (Dep_WebsiteURL), is dbNull
Response.Redirect("MessagePage.aspx?msg=Sorry, no available url for
the moment")
End If
End Sub
I haven't figured out how to get the exact code together yet, but I'm
kind of in a hurry...So any help would very very appreciated !
Thanks,
Fredrik
Hi Fredik, If i follow your pseudo code correctly: Private Sub rptSubjects_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptSubjects.ItemDataBound
if The databound Item, (Dep_WebsiteURL), is dbNull Response.Redirect("MessagePage.aspx?msg=Sorry, no available url for the moment") End If
End Sub
your plan will redirect the user on the databinding event to the message
page if any of the urls are dbnull. This would mean that if _any_ of the
links in the list was dbnull then the user would be automatically redirected
and would not have the opportunity to see the links that were available.
Also from a usability point of view you are forcing the user to view a page
that tells them the link is not available.
IMHO you would be better changing the link text to something like "this link
is not currently available" and disabling the link. You could then display it
inline with the rest of the active links. If you were to do this with
declarative iif statements on the aspx/ascx template instead of ondatabinding
it would have the benefit that you could change the functionality without
recompiling the dll.
If you _really_ want to redirect the user as in the pseudo code you need
something like:
Private Sub rptSubjects_OnItemDataBound(ByVal o As Object, ByVal e As
RepeaterItemEventArgs) Handles rptSubjects.ItemDataBound
If e.Item.ItemIndex > -1 Then
If CType(e.Item.DataItem, DataRowView)("Dep_WebsiteURL") Is
DBNull.Value Then
Response.Redirect("/messagepage.aspx?message=blah blah blah")
End If
End If
End Sub
My suggestion would be to use the following hyperlink in your repeater
template
<asp:HyperLink NavigateUrl='<%# "http://" &
Container.DataItem("Dep_WebsitÂ*eURL") %>' text='<%#
iif(Container.DataItem("Dep_WebsitÂ*eURL") is dbnull.value
,Container.DataItem("SubjectNamÂ*e") & ": link not available",
Container.DataItem("SubjectNamÂ*e") ) enabled="<%# iff(
Container.DataItem("Dep_WebsitÂ*eURL") is dbnull.value, false, true)%>"
Runat="server" Target="_blank"
ID="Hyperlink1" />
which:
1. checks to see if the website url is null
2. if it is null, it replaces the link text to "subject name : link not
available" and disables the link (stops it from being clickable)
if the website url is not null it leaves the link text as "subject name" and
leaves the link enabled.
HTH jd
"fr*******@hotmail.com" wrote:
Hi ! Thanks for the help so far ! I'm getting a little bit closer to solve thism, but I'm not there yet.
Could someone please help me with the code in the ItemDataBound event. What I want is something like this, but in proper vb code off course...
Private Sub rptSubjects_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptSubjects.ItemDataBound
if The databound Item, (Dep_WebsiteURL), is dbNull Response.Redirect("MessagePage.aspx?msg=Sorry, no available url for the moment") End If
End Sub
I haven't figured out how to get the exact code together yet, but I'm kind of in a hurry...So any help would very very appreciated !
Thanks, Fredrik
Hi again !
Thanks a lot "London Calling" ! I think the solution you suggested is
better than what I initially intended, and I've decided to go with it.
Only one little thing left...I get a parse error, because the server
tag is not well formed. I can see why, the " ' " and the <#% tags are
not matched perfectly. I've tried to correct it but I can't seem to get
everything right. Any help would be highly appreciated.
by the way, you know of any good online tutorials concerning
programming like the above ??
thanks,
Fredrik
Hi Frederik,
sorry about that it was a bit sloppy of me... I was typing directly into the
newsgroup box, sometimes I rely on intellisense and highlighting more than I
should, but then thats what it's for...
any way revised code (watch for line wrapping):
<asp:HyperLink
NavigateUrl='<%# iif(Container.DataItem("Dep_WebsiteURL") is DBNull.Value,
"#" , "http://" & Container.DataItem("Dep_WebsiteURL")) %>'
text='<%# iif(Container.DataItem("Dep_WebsiteURL") is dbnull.value,
Container.DataItem("SubjectName") & ": link not available",
Container.DataItem("SubjectName"))%>'
enabled='<%# iff(Container.DataItem("Dep_WebsiteURL") is dbnull.value,
false, true)%>'
Runat="server"
Target="_blank"
ID="Hyperlink1"
/>
In case you havent realised, you wrap attributes in single quotes
(atttribute='value') instead of double quoutes (attribute="value") if the
attribute contains an evaluation that contains quotes, in this case
Container.DataItem("ItemName")
HTH jd
"fr*******@hotmail.com" wrote: Hi again ! Thanks a lot "London Calling" ! I think the solution you suggested is better than what I initially intended, and I've decided to go with it. Only one little thing left...I get a parse error, because the server tag is not well formed. I can see why, the " ' " and the <#% tags are not matched perfectly. I've tried to correct it but I can't seem to get everything right. Any help would be highly appreciated.
by the way, you know of any good online tutorials concerning programming like the above ??
thanks, Fredrik
No offense, but the code bellow is less than ideal for maintaining. If you
just look at it, it isn't overly entuitive what's going on. I'd still favor
the onItemDataBound approach because (a) it doesn't mix your presentation
layer with your presentation logic layer , (b) you get intellisense support
and (c) as your logic needs to grow, exponentially harder will this code be
to maintain.
Karl
--
MY ASP.Net tutorials http://www.openmymind.net/ - New and Improved (yes, the popup is annoying) http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"london calling" <lo***********@discussions.microsoft.com> wrote in message
news:74**********************************@microsof t.com... Hi Frederik,
sorry about that it was a bit sloppy of me... I was typing directly into the newsgroup box, sometimes I rely on intellisense and highlighting more than I should, but then thats what it's for...
any way revised code (watch for line wrapping):
<asp:HyperLink
NavigateUrl='<%# iif(Container.DataItem("Dep_WebsiteURL") is DBNull.Value, "#" , "http://" & Container.DataItem("Dep_WebsiteURL")) %>'
text='<%# iif(Container.DataItem("Dep_WebsiteURL") is dbnull.value, Container.DataItem("SubjectName") & ": link not available", Container.DataItem("SubjectName"))%>'
enabled='<%# iff(Container.DataItem("Dep_WebsiteURL") is dbnull.value, false, true)%>'
Runat="server"
Target="_blank"
ID="Hyperlink1"
/>
In case you havent realised, you wrap attributes in single quotes (atttribute='value') instead of double quoutes (attribute="value") if the attribute contains an evaluation that contains quotes, in this case Container.DataItem("ItemName")
HTH jd
"fr*******@hotmail.com" wrote:
Hi again ! Thanks a lot "London Calling" ! I think the solution you suggested is better than what I initially intended, and I've decided to go with it. Only one little thing left...I get a parse error, because the server tag is not well formed. I can see why, the " ' " and the <#% tags are not matched perfectly. I've tried to correct it but I can't seem to get everything right. Any help would be highly appreciated.
by the way, you know of any good online tutorials concerning programming like the above ??
thanks, Fredrik
Hi Karl, no offense taken, in fact I agree completely. Its just another
_Quick_ (short term at least) solution that allows for a couple of changes
without having to recompile and may conceptually be easier to get started
with. jd
"Karl Seguin" wrote: No offense, but the code bellow is less than ideal for maintaining. If you just look at it, it isn't overly entuitive what's going on. I'd still favor the onItemDataBound approach because (a) it doesn't mix your presentation layer with your presentation logic layer , (b) you get intellisense support and (c) as your logic needs to grow, exponentially harder will this code be to maintain.
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/ - New and Improved (yes, the popup is annoying) http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to come!)
"london calling" <lo***********@discussions.microsoft.com> wrote in message news:74**********************************@microsof t.com... Hi Frederik,
sorry about that it was a bit sloppy of me... I was typing directly into the newsgroup box, sometimes I rely on intellisense and highlighting more than I should, but then thats what it's for...
any way revised code (watch for line wrapping):
<asp:HyperLink
NavigateUrl='<%# iif(Container.DataItem("Dep_WebsiteURL") is DBNull.Value, "#" , "http://" & Container.DataItem("Dep_WebsiteURL")) %>'
text='<%# iif(Container.DataItem("Dep_WebsiteURL") is dbnull.value, Container.DataItem("SubjectName") & ": link not available", Container.DataItem("SubjectName"))%>'
enabled='<%# iff(Container.DataItem("Dep_WebsiteURL") is dbnull.value, false, true)%>'
Runat="server"
Target="_blank"
ID="Hyperlink1"
/>
In case you havent realised, you wrap attributes in single quotes (atttribute='value') instead of double quoutes (attribute="value") if the attribute contains an evaluation that contains quotes, in this case Container.DataItem("ItemName")
HTH jd
"fr*******@hotmail.com" wrote:
Hi again ! Thanks a lot "London Calling" ! I think the solution you suggested is better than what I initially intended, and I've decided to go with it. Only one little thing left...I get a parse error, because the server tag is not well formed. I can see why, the " ' " and the <#% tags are not matched perfectly. I've tried to correct it but I can't seem to get everything right. Any help would be highly appreciated.
by the way, you know of any good online tutorials concerning programming like the above ??
thanks, Fredrik
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Ed Allan |
last post by:
http://ejaconsulting.com/nestedrepeater/NestedRepeater.txt
>-----Original Message-----
>Doh! The HTML has all been rendered . . .
>
>Right click on this link and select 'Save target as ..'
>to...
|
by: Marco Antonio Montalvo Durán |
last post by:
hello everybody!!!,
I made a list of links to different URL's using a Repeater. what I'm trying
to do is to get the position in the repeater where clicked. Does somebody
know how can I do it??...
|
by: Fernando Chilvarguer |
last post by:
My problem:
I have a field in a database table that contains URL info.
The values can be:
1. A Url
2. Null
If the value is null I still need to display the record but not the url
link.
|
by: Alan Silver |
last post by:
Hello,
I have a page in which I'm trying to give the user the chance to
manipulate a list of items. These are the price variations for a
product, so each item consists of a name (eg, small,...
|
by: Tarun Mistry |
last post by:
Hi everyone, a simple problem I hope you guys can help me with.
I have a repeater control, within this i would like to place another server
control.
I.e.
<asp:Repeater id="Repeater1"...
|
by: deathtospam |
last post by:
I've written some code (C# / ASP.NET on .NET v2.0) that allows me to
list all stored procedures in a SQL Server database, along with with
their associated CREATE PROCEDURE statements. Here's an...
|
by: |
last post by:
I have what's probably a simple page lifecycle question related to
dynamically evaluating values that are placed by a repeater and dynmically
placing user controls that use those values.
I'm...
|
by: shapper |
last post by:
Hello,
I am binding a Repeater as follows:
Private Sub rFeedback_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles rFeedback.Load
If Not Page.IsPostBack Then...
|
by: champ.supernova |
last post by:
Hi,
I have a dropdownlist which is repeated inside a repeater. What I'm
wanting is for when one instance of the dropdownlist has its selection
changed, for 1) this to trigger an...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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...
|
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...
|
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,...
| |