By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,121 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

Accessing Server Controls inside a Repeater?

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.