0
我在datalist中使用Itemtemplate和headertemplate。但在HeaderTemplate中的情況下,它是不是查詢字符串值發送到其他頁面查詢字符串不在HeaderTemplate中發送值
下面是DataList控件的代碼brandwise.aspx
<asp:DataList ID="DataList2" runat="server" DataSourceID="SqlDataSource2" >
<HeaderTemplate>
<a href='pc1.aspx?<%# Eval("categoryId","cid={0}") %>' style="text-decoration:none">
ALL BRANDS
</a>
</HeaderTemplate>
<ItemTemplate>
<ul>
<li>
<a href='brandwise.aspx?<%# Eval("categoryId","cid={0}") %>&<%# Eval("brandId","bid={0}") %>' style="text-decoration:none">
<%# Eval("brandName", "{0}") %>
</a>
</li>
</ul>
</ItemTemplate>
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:DBCS %>" SelectCommand="select distinct b.brandName,p.categoryId,b.brandId from Brand1 b, Category c, Product1 p where b.brandId = p.brandId and p.categoryId = c.categoryId and p.categoryId = @cid;">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="" Name="cid" QueryStringField="cid" />
</SelectParameters>
</asp:SqlDataSource>
問題出在下面的頭模板
<HeaderTemplate>
<a href='pc1.aspx?<%# Eval("categoryId","cid={0}") %>' style="text-decoration:none">
ALL BRANDS
</a>
</HeaderTemplate>
,因爲當它重定向在瀏覽器窗口中pc1.aspx它顯示
http://localhost:3492/pc1.aspx?
這意味着它沒有考慮到查詢字符串值和類標識符是已列名。 我基本上爲我的項目製作一個電子商務網站。在這段代碼中,我試圖顯示給定類別的品牌,如亞馬遜。例如,類別可能是「移動」,品牌可能是三星,蘋果,諾基亞。因此,如果用戶點擊某個特定品牌,則會爲該品牌顯示移動設備。而且我還需要包含一個顯示所有品牌的「ALLBRANDS」選項。有什麼我可以這樣做嗎? Plz不要嘗試運行它。它不會。
我用conecpt。我還使用了兩個項目模板,但在這種情況下,目前我正在放入我的headertemplate中的第二個項目模板值不顯示 –
@Ashish Chopra:爲什麼不能將兩個內容放在同一個「ItemTemplate」中? –
因爲我不想重複所有品牌價值的錨標籤 –