473,411 Members | 2,154 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,411 software developers and data experts.

Accessing Server Controls inside a Repeater?

Hi all,
I am using a Repeater in conjunction with a SQLDatasource and SQL Server.
One of the controls in the repeater is a HyperlLink as follows:

<asp:HyperLink NavigateUrl='Search.aspx?page=base&amp;searchid=<%
Eval("sequence")%>' .....

As you can see I am trying to pass a QueryString evaluated at runtime. All
the other Evals of DataFields in the Repeater are working just fine. However
this NavigateUrl is resolving as "request.querystring("searchid") = "<%" at
the destination page. I thought that to solve the problem I would then
simply set the string in the code-behind on Page_Load.

However the documentaion is unclear giving me 2 problems.

In pseudo-code here is what I'm trying to do. I know the syntax is wrong,
but I m just trying to display my intention.....

Dim strNav as String
strNav = "Search.aspx?page=base&amp;searchid=" & Eval("sequence")
Repeater.HyperLink.NavigateURL = strNav

How do I access the HyperLink control in the Repeater?
Do I need to use the SearchControl method to find the HyperLink in the
Repeater?

Also, will a simple call like Eval("sequence") work in the code-beind VB, as
it does in the apsx page where the syntax
<% Eval("sequence")%seems to work for all the data fields called up by
the SQLDatasource control?

Or is there any way to get at the underlying recordset in the SQLDataSource
directly to get the value of a field by name rather than numeric index?

I suppose there might be a better way to get the value of the field
"sequence" to the target page, but for now I am trying QueryString.

Thanks...

Feb 27 '07 #1
4 9035
I think you are missing just one character:

searchid=<%# Eval("sequence")%>

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"John Kotuby" <jo***@powerlist.comwrote in message
news:eJ**************@TK2MSFTNGP04.phx.gbl...
Hi all,
I am using a Repeater in conjunction with a SQLDatasource and SQL Server.
One of the controls in the repeater is a HyperlLink as follows:

<asp:HyperLink NavigateUrl='Search.aspx?page=base&amp;searchid=<%
Eval("sequence")%>' .....

As you can see I am trying to pass a QueryString evaluated at runtime. All
the other Evals of DataFields in the Repeater are working just fine.
However this NavigateUrl is resolving as "request.querystring("searchid")
= "<%" at the destination page. I thought that to solve the problem I
would then simply set the string in the code-behind on Page_Load.

However the documentaion is unclear giving me 2 problems.

In pseudo-code here is what I'm trying to do. I know the syntax is wrong,
but I m just trying to display my intention.....

Dim strNav as String
strNav = "Search.aspx?page=base&amp;searchid=" & Eval("sequence")
Repeater.HyperLink.NavigateURL = strNav

How do I access the HyperLink control in the Repeater?
Do I need to use the SearchControl method to find the HyperLink in the
Repeater?

Also, will a simple call like Eval("sequence") work in the code-beind VB,
as it does in the apsx page where the syntax
<% Eval("sequence")%seems to work for all the data fields called up by
the SQLDatasource control?

Or is there any way to get at the underlying recordset in the
SQLDataSource directly to get the value of a field by name rather than
numeric index?

I suppose there might be a better way to get the value of the field
"sequence" to the target page, but for now I am trying QueryString.

Thanks...

Feb 27 '07 #2
You can always, in code behind, create an onitemdatabound event and in that
event you can access the link directly like so:

// assuming we have a hyperlink in the repeater called link
HyperLink link = (HyperLink)e.Item.FindControl("link");
if(link != null)
{
// do something with the link
link.Text="We did it";
}
--

Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"John Kotuby" <jo***@powerlist.comwrote in message
news:eJ**************@TK2MSFTNGP04.phx.gbl...
Hi all,
I am using a Repeater in conjunction with a SQLDatasource and SQL Server.
One of the controls in the repeater is a HyperlLink as follows:

<asp:HyperLink NavigateUrl='Search.aspx?page=base&amp;searchid=<%
Eval("sequence")%>' .....

As you can see I am trying to pass a QueryString evaluated at runtime. All
the other Evals of DataFields in the Repeater are working just fine.
However this NavigateUrl is resolving as "request.querystring("searchid")
= "<%" at the destination page. I thought that to solve the problem I
would then simply set the string in the code-behind on Page_Load.

However the documentaion is unclear giving me 2 problems.

In pseudo-code here is what I'm trying to do. I know the syntax is wrong,
but I m just trying to display my intention.....

Dim strNav as String
strNav = "Search.aspx?page=base&amp;searchid=" & Eval("sequence")
Repeater.HyperLink.NavigateURL = strNav

How do I access the HyperLink control in the Repeater?
Do I need to use the SearchControl method to find the HyperLink in the
Repeater?

Also, will a simple call like Eval("sequence") work in the code-beind VB,
as it does in the apsx page where the syntax
<% Eval("sequence")%seems to work for all the data fields called up by
the SQLDatasource control?

Or is there any way to get at the underlying recordset in the
SQLDataSource directly to get the value of a field by name rather than
numeric index?

I suppose there might be a better way to get the value of the field
"sequence" to the target page, but for now I am trying QueryString.

Thanks...

Feb 27 '07 #3
Thanks Eliyahu,

Actually that was a typo on my part when I posted the message. The actual
syantax on the page is:
<asp:HyperLink NavigateUrl='Search.aspx?page=base&amp;searchid=<% #
Eval("sequence")%>' ...

I just don't understand why the Eval doesn't relace itself with the value of
the "sequence" field in this context, and why the Request.QueryString is
sending over "<%" as a literal and then just stopping right there rather
than sending the entire unresolved string "<%# Eval("sequence")%>". Maybe
the # character is a delimiter in the QueryString in .NET?

I had noticed something similar happenning when I tried to concatenate a
literal string with an Eval to be the text of a Label control within the
Repeater:

<asp:Label Text='Title: <%# Eval("SearchTitle") %>'
Only the literal part "Title:" was showing up.

and this:
<asp:Label Text='Title: ' & ' <%# Eval("SearchTitle") %>'
Generated a syntax error.

I ended up placing 2 Label controls next to each other, one to hold the
Literal string and the other to hold the Evaluated field expression. That
worked.

"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:%2****************@TK2MSFTNGP04.phx.gbl...
>I think you are missing just one character:

searchid=<%# Eval("sequence")%>

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"John Kotuby" <jo***@powerlist.comwrote in message
news:eJ**************@TK2MSFTNGP04.phx.gbl...
>Hi all,
I am using a Repeater in conjunction with a SQLDatasource and SQL Server.
One of the controls in the repeater is a HyperlLink as follows:

<asp:HyperLink NavigateUrl='Search.aspx?page=base&amp;searchid=<%
Eval("sequence")%>' .....

As you can see I am trying to pass a QueryString evaluated at runtime.
All the other Evals of DataFields in the Repeater are working just fine.
However this NavigateUrl is resolving as "request.querystring("searchid")
= "<%" at the destination page. I thought that to solve the problem I
would then simply set the string in the code-behind on Page_Load.

However the documentaion is unclear giving me 2 problems.

In pseudo-code here is what I'm trying to do. I know the syntax is wrong,
but I m just trying to display my intention.....

Dim strNav as String
strNav = "Search.aspx?page=base&amp;searchid=" & Eval("sequence")
Repeater.HyperLink.NavigateURL = strNav

How do I access the HyperLink control in the Repeater?
Do I need to use the SearchControl method to find the HyperLink in the
Repeater?

Also, will a simple call like Eval("sequence") work in the code-beind VB,
as it does in the apsx page where the syntax
<% Eval("sequence")%seems to work for all the data fields called up by
the SQLDatasource control?

Or is there any way to get at the underlying recordset in the
SQLDataSource directly to get the value of a field by name rather than
numeric index?

I suppose there might be a better way to get the value of the field
"sequence" to the target page, but for now I am trying QueryString.

Thanks...


Feb 27 '07 #4
Thanks Mark for another winning suggestion!

Below is an example of the code I wrote that allowed me to dynamically set
the NavigateUrl property of a HyperLink control withing the Repeater. I have
included it for the benefit of anyone interested in this technique.
In the Declaration of the Repeater control designate the handler for the
OnItemDataBound event.
-------------------------
<asp:Repeater ID="Repeater1" OnItemDataBound="R1_ItemDataBound"
runat="server">
-----------------------

Then in the Code Behind file or within Script tags, assemble a string
variable using the DataItem argument of the RepeaterItemEventArgs that are
passed to the handler. That will pull the value of any Data Field that is
present in the current record being processed.
-------------------------

Sub R1_ItemDataBound(ByVal Sender As Object, ByVal e As
RepeaterItemEventArgs)

' This event is raised for the header, the footer, separators, and items.
Dim hlinkEdit As HyperLink
Dim strURL As String

hlinkEdit = e.Item.FindControl("lnkEdit")

If Not IsDBNull(hlinkEdit) Then
strURL = "~/Search/searchDetail.aspx?page=base&searchId=" &
Trim(e.Item.DataItem("sequence").ToString())
hlinkEdit.NavigateUrl = strURL
End If

End Sub

"Mark Fitzpatrick" <ma******@fitzme.comwrote in message
news:uS*************@TK2MSFTNGP06.phx.gbl...
You can always, in code behind, create an onitemdatabound event and in
that event you can access the link directly like so:

// assuming we have a hyperlink in the repeater called link
HyperLink link = (HyperLink)e.Item.FindControl("link");
if(link != null)
{
// do something with the link
link.Text="We did it";
}
--

Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"John Kotuby" <jo***@powerlist.comwrote in message
news:eJ**************@TK2MSFTNGP04.phx.gbl...
>Hi all,
I am using a Repeater in conjunction with a SQLDatasource and SQL Server.
One of the controls in the repeater is a HyperlLink as follows:

<asp:HyperLink NavigateUrl='Search.aspx?page=base&amp;searchid=<%
Eval("sequence")%>' .....

As you can see I am trying to pass a QueryString evaluated at runtime.
All the other Evals of DataFields in the Repeater are working just fine.
However this NavigateUrl is resolving as "request.querystring("searchid")
= "<%" at the destination page. I thought that to solve the problem I
would then simply set the string in the code-behind on Page_Load.

However the documentaion is unclear giving me 2 problems.

In pseudo-code here is what I'm trying to do. I know the syntax is wrong,
but I m just trying to display my intention.....

Dim strNav as String
strNav = "Search.aspx?page=base&amp;searchid=" & Eval("sequence")
Repeater.HyperLink.NavigateURL = strNav

How do I access the HyperLink control in the Repeater?
Do I need to use the SearchControl method to find the HyperLink in the
Repeater?

Also, will a simple call like Eval("sequence") work in the code-beind VB,
as it does in the apsx page where the syntax
<% Eval("sequence")%seems to work for all the data fields called up by
the SQLDatasource control?

Or is there any way to get at the underlying recordset in the
SQLDataSource directly to get the value of a field by name rather than
numeric index?

I suppose there might be a better way to get the value of the field
"sequence" to the target page, but for now I am trying QueryString.

Thanks...


Feb 27 '07 #5

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

Similar topics

3
by: DonRex | last post by:
Hello all! I couldn't find a web application-newsgroup for ASP.NET, so I'm sorry if this is the wrong forum! Synopsis: In my webform I have 3 nested repeaters: rpWeeks ----- rpTime
0
by: Jeff | last post by:
After I bind the repeater control in the form_load event, it builds multiple lines based on the number of rows in the dataset. In the repeater control, I have a textbox and a dropdown list box. ...
4
by: John Holmes | last post by:
I'm using data to rename some web controls on a form that uses a repeater contol and so it can have mulitple instances of the same control set. The controls get renamed (thanks to Steven Cheng's...
9
by: Ric | last post by:
im new to asp.net. please help if u can. is it possible to refer to a control(ie lable, placeholder, textbox) that is inside a repeater object from a code behind file? when i place the control...
5
by: serge calderara | last post by:
Dear all, I am new in asp.net and prepare myself for exam I still have dificulties to understand the difference between server control and HTML control. Okey things whcih are clear are the fact...
3
by: Iain Buchanan | last post by:
Moving this code below from v1.1 to 2.0... am now getting this bug... After I bind a repeater I move the repeater inside the placeholder using controls.add(), but when I do this, all the...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
1
by: Dave | last post by:
I have the following ASP.NET 2.0 code (simplified here for ease): <asp:Repeater id="SearchResultsRepeater" runat="server"> <ItemTemplate> <uc:SearchResult ID="SearchResult"...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
marktang
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,...
0
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,...
0
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...
0
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,...
0
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...

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.