473,327 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

repeater - Parse Error

Hi everybody !

With help from some nice people here I'm getting close to solve my
problem with dbnull values in a repeater.
I got it pretty much done, I just ned to fix some syntax.

I get a parse error on this code because it's not well formed.
Can someone please take a look at it and try to find what I'm doing
wrong...I've been staring at it for so long now I can't tell up from
down. I know it has to be a "'" or a '"' somewhere that's not correctly
matched...

The logic looks right so I guess all that's left to be done is fixing
the syntactic bugs...(easier said than done :-)

see code below...(the table cell within the item template in the
repeater)

as always...thanks a million

Fredrik

<td>
<asp:HyperLink NavigateUrl='<%# "http://" &
Container.DataItem("Dep_WebsiteURL") %>' text='<%#
Iif(Container.DataItem("Dep_WebsiteURL") is dbnull.value,
Container.DataItem("SubjectName") & ": link not available",
Container.DataItem("SubjectName")) %>'enabled='<%#
Iif(Container.DataItem("Dep_WebsiteURL") is dbnull.value, false,
true)%>'
Runat="server" Target="_blank" ID="Hyperlink1" />
</td>

Nov 19 '05 #1
1 2042
Hi Fredrik, you may have noticed Karl's update on one of your other threads
about it being better to use the ItemDataBound event. It's a very good point.

Below is a test you can compile and run where both techniques are used, you
can decide which is better for your situation. To test it with your data you
will need to change repeater.datasource = getDummyDatasource() to a function
that returns a datatable with your own data:

HTH jd

*************************************************
Begin Template - paste this into a new aspx document (between the form tags)
*************************************************
<h3>formatted using ItemDataBound event</h3>
<asp:Repeater id="Repeater1" runat="server">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:HyperLink ID="Hyperlink1" Runat="server" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<h3>formatted using statements inline in the template</h3>
<asp:Repeater id="Repeater2" runat="server">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:HyperLink NavigateUrl='<%# Container.DataItem("Dep_WebsiteURL")
%>'
text='<%#IIf(Container.DataItem("Dep_WebsiteURL") is dbnull.value,
Container.DataItem("SubjectName") & ": link not available",
Container.DataItem("SubjectName")) %>'

enabled='<%# Iif(Container.DataItem("Dep_WebsiteURL") is
dbnull.value, false, true)%>'
Runat="server" Target="_blank" ID="Hyperlink2" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>

*************************************************
End Template
__________________________________________________ ______
Begin Code Behind
paste this into the codebehind and delete the original page_load
note if you put the template code in first and switch to design mode
vs will probably put the repeater declarations in for you so you may
have to delete them from this code.
*************************************************

Protected WithEvents Repeater1 As System.Web.UI.WebControls.Repeater
Protected WithEvents Repeater2 As System.Web.UI.WebControls.Repeater
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

If Not Page.IsPostBack Then
BindRepeaters()
End If

End Sub

Private Sub BindRepeaters()
Dim odt As DataTable = getDummyDataSource()
'link created using ItemDataBound event
Me.Repeater1.DataSource = odt
Me.Repeater1.DataBind()

'link created in template
Me.Repeater2.DataSource = odt
Me.Repeater2.DataBind()

End Sub

Private Function getDummyDataSource() As DataTable

Dim odt As New DataTable("DummyData")
With odt.Columns
.Add("Dep_WebsiteUrl", GetType(String))
.Add("SubjectName", GetType(String))
End With

With odt.Columns("Dep_WebsiteUrl")
.AllowDBNull = True
End With

For i As Integer = 0 To 10
Dim r As DataRow = odt.NewRow
r("Dep_WebsiteUrl") = IIf(i Mod 3 = 0, DBNull.Value,
"http://website" & i.ToString)
r("SubjectName") = "subject" & i.ToString
odt.Rows.Add(r)
Next

Return odt
End Function

Private Sub Repeater1_ItemDataBound(ByVal o As Object, ByVal e As
WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound
Dim repeaterItem As WebControls.RepeaterItem = e.Item

If repeaterItem.ItemIndex > -1 Then
Dim hyper As WebControls.HyperLink =
repeaterItem.FindControl("Hyperlink1")

Dim data As DataRowView = CType(repeaterItem.DataItem,
DataRowView)

If data("Dep_WebsiteUrl") Is DBNull.Value Then
With hyper
.Text = data("SubjectName") & " : link not available"
.Enabled = False
.NavigateUrl = "#"
End With
Else
With hyper
.Text = data("SubjectName")
.Enabled = True
.NavigateUrl = data("Dep_WebsiteUrl")
End With
End If
End If

End Sub

*************************************************
End Code Behind
*************************************************

"fr*******@hotmail.com" wrote:
Hi everybody !

With help from some nice people here I'm getting close to solve my
problem with dbnull values in a repeater.
I got it pretty much done, I just ned to fix some syntax.

I get a parse error on this code because it's not well formed.
Can someone please take a look at it and try to find what I'm doing
wrong...I've been staring at it for so long now I can't tell up from
down. I know it has to be a "'" or a '"' somewhere that's not correctly
matched...

The logic looks right so I guess all that's left to be done is fixing
the syntactic bugs...(easier said than done :-)

see code below...(the table cell within the item template in the
repeater)

as always...thanks a million

Fredrik

<td>
<asp:HyperLink NavigateUrl='<%# "http://" &
Container.DataItem("Dep_WebsiteURL") %>' text='<%#
Iif(Container.DataItem("Dep_WebsiteURL") is dbnull.value,
Container.DataItem("SubjectName") & ": link not available",
Container.DataItem("SubjectName")) %>'enabled='<%#
Iif(Container.DataItem("Dep_WebsiteURL") is dbnull.value, false,
true)%>'
Runat="server" Target="_blank" ID="Hyperlink1" />
</td>

Nov 19 '05 #2

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

Similar topics

2
by: Calvin Lai | last post by:
Hi all, I have a repeater control trying to display some info including date information to the client. I used the following: <%# DataBinder.Eval(Container.DataItem, "Date", "DataTime.Parse({0},...
3
by: Mark | last post by:
I am looking for an example of using checkboxes in a repeater control where the checkbox state is persisted from page to page. Thank you, Mark
1
by: Sandy | last post by:
I have a repeater which shows Group names. (Skip this part if you want rather irrelevant) The groups are ordered and formatted: Parent ---Child ------Grand Child (okay start reading again...
2
by: Keith Harris | last post by:
Hi, I have a reapeater control with linkbutton controls in the item template section. An array of USER objects will be the data source and I want to embed USER.id as the CommandArgument so...
8
by: I am Sam | last post by:
Hi everyone, This problem is making me old. I don't want to get any older. I have a multi-nested repeater control as follows: <asp:Repeater ID="clubRep1" Runat="server">...
1
by: ratnakarp | last post by:
Hi, I have a search text box. The user enters the value in the text box and click on enter button. In code behind on button click i'm writing the code to get the values from the database and...
8
by: fernandezr | last post by:
I would like to use a user control as a template inside a repeater. Some of the fields in the control should be hidden depending on whether or not there is data. I'm still a ASP .Net newbie so the...
4
by: Brad Baker | last post by:
I'm going a little crazy :) I'm trying to bind a repeater control to a dataset on page load using the following code: if (Request.QueryString != null) { string customerid = Request.QueryString;...
0
by: Eugene Anthony | last post by:
The problem with my coding is that despite removing the records stored in the array list, the rptPages repeater control is still visible. The rptPages repeater control displayes the navigation...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.