473,804 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

hyperlink in repeater...what if url is dbNull ??

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:HyperLin k NavigateUrl='<% # "http://" &
Container.DataI tem("Dep_Websit *eURL") %>' text='<%#
Container.DataI tem("SubjectNam *e") %>' Runat="server" Target="_blank"
ID="Hyperlink1 " />
</td>
</tr>
</table>
</ItemTemplate>
</asp:repeater>
------------------------------*-----------------------------

Nov 19 '05 #1
8 3168
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*******@hotm ail.com> wrote in message
news:11******** *************@g 44g2000cwa.goog legroups.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:HyperLin k NavigateUrl='<% # "http://" &
Container.DataI tem("Dep_Websit *eURL") %>' text='<%#
Container.DataI tem("SubjectNam *e") %>' Runat="server" Target="_blank"
ID="Hyperlink1 " />
</td>
</tr>
</table>
</ItemTemplate>
</asp:repeater>
------------------------------*-----------------------------
Nov 19 '05 #2
You could use an iif statement (Assuming VB) e.g
iif(container.d ataitem("Dep_We bsiteURL") is dbnull.value,
"/messagepage.asp x?message=..... ", container.datai tem("Dep_Websit eURL"))

or you could use the same technique to enable/disable the link or change the
link text... jd

"fr*******@hotm ail.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:HyperLin k NavigateUrl='<% # "http://" &
Container.DataI tem("Dep_Websit Â*eURL") %>' text='<%#
Container.DataI tem("SubjectNam Â*e") %>' Runat="server" Target="_blank"
ID="Hyperlink1 " />
</td>
</tr>
</table>
</ItemTemplate>
</asp:repeater>
------------------------------Â*-----------------------------

Nov 19 '05 #3
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_Ite mDataBound(ByVa l sender As Object, ByVal e
As System.Web.UI.W ebControls.Repe aterItemEventAr gs) Handles
rptSubjects.Ite mDataBound

if The databound Item, (Dep_WebsiteURL ), is dbNull
Response.Redire ct("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

Nov 19 '05 #4
Hi Fredik, If i follow your pseudo code correctly:
Private Sub rptSubjects_Ite mDataBound(ByVa l sender As Object, ByVal e
As System.Web.UI.W ebControls.Repe aterItemEventAr gs) Handles
rptSubjects.Ite mDataBound

if The databound Item, (Dep_WebsiteURL ), is dbNull
Response.Redire ct("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_OnI temDataBound(By Val o As Object, ByVal e As
RepeaterItemEve ntArgs) Handles rptSubjects.Ite mDataBound

If e.Item.ItemInde x > -1 Then

If CType(e.Item.Da taItem, DataRowView)("D ep_WebsiteURL") Is
DBNull.Value Then

Response.Redire ct("/messagepage.asp x?message=blah blah blah")

End If

End If

End Sub

My suggestion would be to use the following hyperlink in your repeater
template

<asp:HyperLin k NavigateUrl='<% # "http://" &
Container.DataI tem("Dep_Websit Â*eURL") %>' text='<%#
iif(Container.D ataItem("Dep_We bsitÂ*eURL") is dbnull.value
,Container.Data Item("SubjectNa mÂ*e") & ": link not available",
Container.DataI tem("SubjectNam Â*e") ) enabled="<%# iff(
Container.DataI tem("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*******@hotm ail.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_Ite mDataBound(ByVa l sender As Object, ByVal e
As System.Web.UI.W ebControls.Repe aterItemEventAr gs) Handles
rptSubjects.Ite mDataBound

if The databound Item, (Dep_WebsiteURL ), is dbNull
Response.Redire ct("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

Nov 19 '05 #5
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

Nov 19 '05 #6
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:HyperLin k

NavigateUrl='<% # iif(Container.D ataItem("Dep_We bsiteURL") is DBNull.Value,
"#" , "http://" & Container.DataI tem("Dep_Websit eURL")) %>'

text='<%# iif(Container.D ataItem("Dep_We bsiteURL") is dbnull.value,
Container.DataI tem("SubjectNam e") & ": link not available",
Container.DataI tem("SubjectNam e"))%>'

enabled='<%# iff(Container.D ataItem("Dep_We bsiteURL") is dbnull.value,
false, true)%>'

Runat="server"

Target="_blank"

ID="Hyperlink1 "

/>

In case you havent realised, you wrap attributes in single quotes
(atttribute='va lue') instead of double quoutes (attribute="val ue") if the
attribute contains an evaluation that contains quotes, in this case
Container.DataI tem("ItemName")

HTH jd

"fr*******@hotm ail.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

Nov 19 '05 #7
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.mic rosoft.com> wrote in message
news:74******** *************** ***********@mic rosoft.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:HyperLin k

NavigateUrl='<% # iif(Container.D ataItem("Dep_We bsiteURL") is DBNull.Value,
"#" , "http://" & Container.DataI tem("Dep_Websit eURL")) %>'

text='<%# iif(Container.D ataItem("Dep_We bsiteURL") is dbnull.value,
Container.DataI tem("SubjectNam e") & ": link not available",
Container.DataI tem("SubjectNam e"))%>'

enabled='<%# iff(Container.D ataItem("Dep_We bsiteURL") is dbnull.value,
false, true)%>'

Runat="server"

Target="_blank"

ID="Hyperlink1 "

/>

In case you havent realised, you wrap attributes in single quotes
(atttribute='va lue') instead of double quoutes (attribute="val ue") if the
attribute contains an evaluation that contains quotes, in this case
Container.DataI tem("ItemName")

HTH jd

"fr*******@hotm ail.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

Nov 19 '05 #8
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.mic rosoft.com> wrote in message
news:74******** *************** ***********@mic rosoft.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:HyperLin k

NavigateUrl='<% # iif(Container.D ataItem("Dep_We bsiteURL") is DBNull.Value,
"#" , "http://" & Container.DataI tem("Dep_Websit eURL")) %>'

text='<%# iif(Container.D ataItem("Dep_We bsiteURL") is dbnull.value,
Container.DataI tem("SubjectNam e") & ": link not available",
Container.DataI tem("SubjectNam e"))%>'

enabled='<%# iff(Container.D ataItem("Dep_We bsiteURL") is dbnull.value,
false, true)%>'

Runat="server"

Target="_blank"

ID="Hyperlink1 "

/>

In case you havent realised, you wrap attributes in single quotes
(atttribute='va lue') instead of double quoutes (attribute="val ue") if the
attribute contains an evaluation that contains quotes, in this case
Container.DataI tem("ItemName")

HTH jd

"fr*******@hotm ail.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


Nov 19 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
5407
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 get the code in a text file. > >Thanks - Ed >
1
1180
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?? I'll really appreciate your help
4
8025
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.
1
2297
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, medium, large), a price, a checkbox to say whether or not the variation is on special offer and a special price. I can pull the values out of the database OK and display them in a repeater. What I want to do is have a set of controls below the...
2
1136
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" runat="server"> <HeaderTemplate></HeaderTemplate> <ItemTemplate>
3
1614
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 excerpt from that code: ============================================ <asp:Repeater runat="server" ID="StoredProcedureCheckboxList"> <HeaderTemplate> <table border="0" cellpadding="0" cellspacing="3" width="100%"> <tr style="height:0px;">
7
3010
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 attempting to bind a user control I've written, "ImageBox", to a repeater. The user control takes a custom property, "ContentID", that will execute a database lookup and load an image.
2
7079
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 rFeedback.DataSource = "rFeedback_DataSource" rFeedback.DataBind()
1
7361
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 'OnSelectedIndexChanged' subroutine, and 2) for that subroutine to be able to somehow identify which 'row' of the repeater the dropdownlist belongs to. To keep things simple, I'm posting just the relevant parts of the code below...
0
9595
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10603
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10353
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10099
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9176
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6869
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4314
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 we have to send another system

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.