views:

133

answers:

2

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 />
+2  A: 

If you include an anchor tag, you would be able to reference it in the URL via the sharp mark:

http://www.site.com/page.aspx#Info

<asp:Repeater runat="server" ID="MyRepeater">
    <ItemTemplate>
        <a name='<%# Eval("Info") %>' style="display: none;"></a>
        <uc1:MyControl ID="Control1" runat="server" 
                 Date='<%# Eval("Date") %>' 
                 Info='<%# Eval("Info") %>' />
    </ItemTemplate>
</asp:Repeater>
Tom Halladay
I added a display: none and removed the extra </a> tag from the (now deleted) other response. See if that helps with the master page.
Tom Halladay
This doesn't seem to work, and it caused the formatting of the master page to return to default formatting.
pm_2
Can you please post an example of the ASP.NET or rendered HTML from within your UserControl? And your masterpage would also be helpful.
Tom Halladay
See latest EDIT. I'm not sure what you would want to see from the master page - it's basically a standard master page with a placeholder and some images (which don't display once the page is referenced as Page/#Key
pm_2
+2  A: 

Try this code for your user control (you don't need Javascript):

<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=&lt;%# lblKey.Text %>"  
    scrolling="no"  
    frameborder="0"          
    style="border:none; overflow:hidden;  
    width:450px; height:80px;"> 
</iframe> 
<br />
lulhuh
Thanks for that, but the real problem that I have here is that http://mysite.com/page/#Key does not find the correct tag and seems to affect the master page formatting.
pm_2
Hi, then you can try this: <a name='<%# Eval("[\"Key\"]") %>' style="visibility: hidden;"></a>this is some bug that if you specify "display: none" then you can't use anchor.
lulhuh