I have a repeater that displays a custom user control on a form multiple times as follows:
<asp:Repeater runat="server" ID="MyRepeater"
ondatabinding="MyRepeater_DataBinding" >
<ItemTemplate>
<a name='<%# Eval("[\"Key\"]") %>' style="display: none;"></a>
<uc1:MyControl ID="Control1" runat="server"
Info='<%#Eval("[\"Info\"]") %>' Date='<%#Eval("[\"Date\"]") %>'
Key='<%#Eval("[\"Key\"]") %>' />/>
</ItemTemplate>
</asp:Repeater>
Binding this to a SQL data source correctly displays the information that I expect:
SqlDataSource.SelectCommand =
"SELECT Info, Date, Key " +
"FROM [dbo].[Test] ";
SqlDataSource.SelectCommandType = SqlDataSourceCommandType.Text;
DataView resultsdv = (DataView)SqlDataSource.Select(DataSourceSelectArguments.Empty);
MyRepeater.DataSource = resultsdv.Table.Rows;
MyRepeater.DataBind();
What I can’t work out is how to reference an individual element of this to go directly to the specific item that I want, for example, to link an item from another web-site. I’m trying to use the Facebook “Like” function, and so I believe I need a URL that will take me directly to the item in question. Can anyone point me in the right direction on this, please?
EDIT:
What I'm looking for is a way to reference a single item within the data repeater from outside the web-site. For example:
http://www.mywebsite.com/MyPage/InfoItem3
EDIT:
Changed above code to reflect answers given using an tag. Trying to reference the page using:
http://www.mywebsite.com/MyPage#Key
e.g.
http://www.mywebsite.com/MyPage#10
Simply reloads the page
EDIT:
HTML from the user control:
<script type="text/javascript" >
$(function() {
var iframe = $("#likeButton");
var newSrc = iframe.attr("src");
newSrc += encodeURIComponent(location.href) + "<%= lblKey.Text %>";
iframe.attr("src", newSrc);
});
</script>
<asp:Label runat="server" ForeColor="blue" Text="Date" Font-Bold="true" Font-Size="Smaller" ID="lblDate" Width="100%" />
<br />
<asp:Label runat="server" Text="Info" ID="lblInfo" Font-Size="Smaller" />
<br />
<asp:Label runat="server" Text="Key" ID="lblKey" Font-Size="Smaller" Visible="true" />
<br />
<iframe id="likeButton"
src="http://www.facebook.com/plugins/like.php?href="
scrolling="no"
frameborder="0"
style="border:none; overflow:hidden;
width:450px; height:80px;">
</iframe>
<br />