2017-08-01 4 views
2

を得た方法、私がリピーターと、以下のようにevalをデータベースから製品を引っ張っ:私は何はリピータインサイドダイナミックボタンに/私は常に私が作ったウェブサイトのホームページで同じ値

<div class="col-md-12 grid-gallery overflow-hidden"> 
    <div class="tab-content"> 
     <ul class="grid masonry-items"> 
      <asp:Repeater ID="RptrProductInfo" runat="server" DataSourceID="SqlDtSourceProductInfo"> 
       <ItemTemplate> 
        <li class="<%#Eval("productcategory") %>"> 
         <figure> 
          <div class="gallery-img"><asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click"><img src="<%#Eval("prouctimage") %>" alt="" /></asp:LinkButton></div> 
          <figcaption> 
           <asp:Label ID="LblProductID" runat="server" Text='<%#Eval("productid") %>'></asp:Label> 
           <h3><%#Eval("productname") %></h3> 
           <p>Ürün hakkında detaylı bilgi için tıklayınız.</p> 
          </figcaption> 
         </figure> 
        </li> 
       </ItemTemplate> 
      </asp:Repeater> 
      <asp:SqlDataSource ID="SqlDtSourceProductInfo" runat="server" ConnectionString="<%$ ConnectionStrings:aytasarimConnectionString %>" SelectCommand="SELECT [productid], [productname], [productcategory], [productimage] FROM [product]"></asp:SqlDataSource> 
     </ul> 
    </div> 
</div> 

LinkBut​​tonを使用して製品をクリックすると、セッションの次のページに製品のIDが転送され、関連する製品IDと製品のその他のプロパティ(製品イメージ、説明、価格など)が一覧表示されます。 。しかし、クリックした商品をクリックすると、最初の商品IDはID番号1のみとなります。たとえば、3番目の商品をクリックすると、同じID情報が他のページ(ID 1)に表示されます。私は何かをクリックすると常にID 1を取得します。少しの研究の後で; LinkBut​​tonを動的にする必要があることを知りました。しかし、私はそれをどうやって行うのか分かりません。私のホームページaspx.csコードは以下の通りです:

実際の問題はコードが私がクリックしたことを知らないと思います。どうすればこの問題を解決できますか?

そして、これは私のproduct.aspxページです:

<section> 
    <div class="container"> 
     <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1"> 
      <ItemTemplate> 
       <div class="row"> 
        <div class="col-md-6 col-sm-12 zoom-gallery sm-margin-bottom-ten"> 
         <a href="<%#Eval("productimage") %>"><img src="<%#Eval("productimage") %>" alt=""/></a> 
        </div> 
        <div class="col-md-5 col-sm-12 col-md-offset-1"> 
         <span class="product-name-details text-uppercase font-weight-600 letter-spacing-2 black-text"><%#Eval("productname") %></span> 
         <p class="text-uppercase letter-spacing-2 margin-two">Stok Durumu: <%#Eval("stock") %></p> 
         <div class="separator-line bg-black no-margin-lr margin-five"></div> 
         <p><%#Eval("description") %></p> 
         <span class="price black-text title-small"><%#Eval("price") %></span> 
         <div class="col-md-9 col-sm-9 no-padding margin-five"> 
          <a class="highlight-button-dark btn btn-medium button" href="shop-cart.html"><i class="icon-basket"></i> Add To Cart</a> 
         </div> 
        </div> 
       </div> 
      </ItemTemplate> 
     </asp:Repeater> 
     <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:aytasarimConnectionString %>" SelectCommand="SELECT [productid], [productname], [stock], [description], [price], [productimage] FROM [product] WHERE ([productid] = @productid)"> 
     <SelectParameters> 
      <asp:SessionParameter Name="productid" SessionField="productid" Type="Int32" /> 
     </SelectParameters> 
     </asp:SqlDataSource> 
    </div> 
</section> 

答えて

1

それはあなたが不要なコードの多くを使用しているように私には見えます。あなたはラベルから文字列としてプロダクトIDを取得し、次にRepeaterをループしながら同じIDを取得するためにデータベースクエリを実行します。

私があなただったらOnClickの代わりにOnCommandを使用し、 a CommandArgument

だから、ASPXで

protected void LinkButton1_Command(object sender, CommandEventArgs e) 
{ 
    Session["productid"] = e.CommandArgument.ToString(); 
    Response.Redirect("product.aspx"); 
} 
の背後にあるコードで

<asp:LinkButton ID="LinkButton1" runat="server" OnCommand="LinkButton1_Command" 
    CommandArgument='<%# Eval("productid") %>'>LinkButton</asp:LinkButton> 

そしてにLinkBut​​tonコントロールを変更

関連する問題