2012-03-14 53 views
2

我有一個顯示約20個產品列表的ASP.NET 4.0主頁。每個產品列表都會生成以下格式的網址:/DisplayProduct.aspx?ProdID=XASP.NET用戶控件中的Google Plus

我想要在每個列表前面顯示收到的每件產品上市的Google Plus和ReTweets的數量。我怎樣才能以最佳優化的方式做到這一點,而不會對頁面加載速度造成太大影響。必須使用哪些腳本?

這裏的用戶控件的代碼

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ProductListing.ascx.cs" Inherits="Controls.ProductListing" %> 

<asp:GridView ID="gvProducts" runat="server" AllowPaging="True" AutoGenerateColumns="False" 
    DataKeyNames="ID" DataSourceID="objProds" PageSize="10" ShowHeader="False" 
    OnRowDataBound="gvProducts_RowDataBound" OnRowCommand="gvProducts_RowCommand" 
    > 
    <Columns> 
     <asp:TemplateField HeaderText="Product List"> 
     <HeaderStyle /> 
     <ItemTemplate> 
      <div class="plist"> 
      <table cellpadding="0" cellspacing="0" style="width: 100%;"> 
    <tr><td>    
       <div class="productname"> 
       <asp:HyperLink runat="server" ID="hypName" Text='<%# Eval("Name") %>' 
        NavigateUrl='<%# "~/DisplayProduct.aspx?ID=" + Eval("ProdID") %>'/> 
       </div>    
      </td> </tr> 
      </table> 
      <div class="productdesc"> 
      <b>Description: </b> 
      <asp:Literal runat="server" ID="lblDesc" Text='<%# Eval("Description") %>' /> 
      </div> 
      </div> 
     </ItemTemplate>   
     </asp:TemplateField> 
    </Columns> 
</asp:GridView> 

回答

1

你應該做這樣的事情

<!-- Place this tag where you want the +1 button to render --> 
<g:plusone size="small" annotation="none" href="http://www.yourwebsite.com/DisplayProduct.aspx?ProdID=<%# Eval("Name") %>"></g:plusone> 

以上是您想用不同的URL指向該產品重複每個產品什麼頁。

下面的腳本不應該重複。

<!-- Place this render call where appropriate --> 
<script type="text/javascript"> 
    (function() { 
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; 
    po.src = 'https://apis.google.com/js/plusone.js'; 
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); 
    })(); 
</script> 

希望它有幫助。

+0

我應該在用戶控件中添加這個腳本嗎?它適合哪裏?此外,產品網址正在動態創建。因此,我可以在> g:plusone腳本 – CuriousDev 2012-03-14 15:33:13

+0

中指定它,您應該按照您在鏈接中設置NavigateUrl的相同方式分配href。理想情況下,腳本應放置在頁面的底部(因此瀏覽器將首先顯示內容,然後關注腳本) – 2012-03-14 15:39:49

+0

我會將此腳本保留在頁面底部,因爲您可能在其他位置有g +按鈕。 – 2012-03-14 15:41:27