簡體   English   中英

如何在ASP.NET中的html標記中使用選擇參數

[英]How to use select parameters in html tags in ASP.NET

            <asp:SqlDataSource ID="SqlKitapDataSoruce" runat="server" 
                ConnectionString="<%$ ConnectionStrings:DatabaseProjeConnectionString %>" 
                SelectCommand="SELECT * FROM [Kitap] ORDER BY [satisSayisi] DESC" >

            </asp:SqlDataSource>
            <% for(int i = 0; i < 5; i++) %>
                <% { %>

                    <div class="indexKitap">
                        <asp:ImageButton ID="<% %>" runat="server" ImageUrl="<%  %>" />
                        <asp:Label ID="LblKitapAd" runat="server" Text="<% %>"></asp:Label>
                    </div>

我有這段代碼,我想將名為foto_path的列用作ImageUrl,將kitap_ad用作標簽的Text,但是我不知道如何在html標記中使用數據源的參數。 我嘗試使用類似<%#foto_path%>但是它給出了錯誤。 如何在html標記中使用數據源的參數?

您必須使用數據綁定控件,例如Repeater 就像是:

<asp:Repeater runat="server" DataSourceID="SqlKitapDataSoruce">
    <ItemTemplate>
        <div class="indexKitap">
            <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl='<%# Eval("foto_path")  %>' />
            <asp:Label ID="LblKitapAd" runat="server" Text='<%# Eval("kitap_ad") %>'></asp:Label>
        </div>
    </ItemTemplate>
</asp:Repeater>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM