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>
我是什麼試圖做的是:當用戶使用LinkButton點擊產品時,它會將產品的ID轉移到下一個會話頁面,並列出相關產品ID和產品的其他屬性(產品圖片,說明,價格等) 。但點擊我點擊的產品只會收到第一個產品ID是ID號1.例如,我點擊第三個產品,然後相同的ID信息出現在另一個頁面上(ID 1)。無論我點擊什麼,我總是會獲得ID 1。經過一點研究;我瞭解到我需要使LinkButton動態。但我不知道該怎麼做。我的主頁aspx.cs代碼如下:
protected void LinkButton1_Click(object sender, EventArgs e)
{
foreach (RepeaterItem item in RptrProductInfo.Items)
{
Label lblName = (Label)item.FindControl("LblProductID");
if (lblName != null)
{
string mesaj = "";
DataRow drLogin = function.GetDataRow("SELECT productid FROM product WHERE productid='" + lblName.Text + "'");
if(drLogin == null)
{
mesaj = "<script>alert('Error!');</script>";
Response.Write(mesaj);
}
else
{
Session["productid"] = drLogin["productid"].ToString();
Response.Redirect("product.aspx");
}
}
}
}
我認爲真正的問題是代碼不知道我點擊了哪一個。我怎麼解決這個問題?
這是我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>