【问题标题】:How to use select parameters in html tags in ASP.NET如何在 ASP.NET 的 html 标记中使用选择参数
【发布时间】:2015-05-26 19:04:24
【问题描述】:
            <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 作为标签的文本,但我不知道如何在 html 标记中使用数据源的参数。我尝试像&lt;%#foto_path%&gt; 一样使用,但它给出了错误。如何在 html 标签中使用数据源的参数?

【问题讨论】:

  • 如果你不知道i(我们数据源中的记录数)的值,你会怎么做? for 循环的内容如何知道它与 SqlKitapDataSoruce 数据源相关联?查理的回答是做你想做的事的一种方式。 asp.net 是您可以查看以了解更多信息或开始的起点之一。

标签: c# html asp.net datasource


【解决方案1】:

您必须使用数据绑定控件,例如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>

【讨论】:

  • 记得把内容放在item template: &lt;ItemTemplate&gt;...&lt;/ItemTemplate&gt;里面的repeater控件中
猜你喜欢
  • 2010-09-16
  • 2016-01-12
  • 1970-01-01
  • 1970-01-01
  • 2012-06-08
  • 2016-11-18
  • 2015-06-06
  • 2013-03-23
  • 2015-07-05
相关资源
最近更新 更多