简体   繁体   English

数据列表不显示项目 ASP.NET

[英]Datalist not displaying items ASP.NET

I have a serious problem with data list I HATE IT so much.我对数据列表有一个严重的问题,我非常讨厌它。 I have a list of data that displays cart items in a table.. basic right?我有一个在表格中显示购物车项目的数据列表.. 基本对吗?

Sure, but not for data list.当然,但不适用于数据列表。 its like data list says I MUST DESTROY YOU.它像数据列表说我必须摧毁你。 The data list does not show any items that I should display!数据列表没有显示任何我应该显示的项目!

Here are some screenshots that will let you understand my issue here.这里有一些截图可以让你在这里理解我的问题。

问题的活生生的例子

从视觉工作室它显示项目

So basically the items are displayed in VS, but in the web application it doesn't.所以基本上这些项目都显示在 VS 中,但在 web 应用程序中却没有。

PLEASE HELP:(请帮忙:(

Here is the code:这是代码:

<div class="container-sm cart-page">
    <table>
        <tr>
            <th>المنتج</th>
            <th>الكمية</th>
            <th>السعر الفرعي</th>
        </tr>
        <asp:DataList ID="DataList1" runat="server" RepeatColumns="1" RepeatLayout="Flow">
            <ItemTemplate>
                <tr>
                    <td>
                        <div class="cart-info">
                            <img src="http://bestjquery.com/tutorial/product-grid/demo8/images/img-1.jpg" alt="camera">
                            <div>
                                <p>Camera 211</p>
                                <small>السعر: 50 ر.س.</small>
                                <br>
                                <a href="#">حذف</a>
                            </div>
                        </div>
                    </td>
                    <td>
                        <input type="number" value="1" min="1" max="10"></td>
                    <td>50 ر.س.</td>
                </tr>
            </ItemTemplate>
        </asp:DataList>
    </table>
    <div class="total-price">
        <table>
            <tr>
                <td class="titles">السعر الفرعي</td>
                <td>150 ر.س.</td>
            </tr>
            <tr>
                <td class="titles">VAT</td>
                <td>22.50 ر.س.</td>
            </tr>
            <tr>
                <td class="titles">المجموع</td>
                <td>172.50 ر.س.</td>
            </tr>
            <tr>
                <td>
                    <a href="store.aspx">
                        <button type="submit" class="btn btn-primary btn-continue-shopping">إكمال التسوق</button>
                    </a>
                </td>
                <td>
                    <a href="checkout.aspx">
                        <button type="submit" class="btn btn-primary btn-checkout">إكمال الدفع</button>
                    </a>
                </td>
            </tr>
        </table>
    </div>
</div>

You need to set the DataSource property with some list or table of data.您需要使用一些数据列表或表格来设置DataSource属性。

Here is a link to the MSDN article: https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.basedatalist.datasource?view=netframework-4.8#System_Web_UI_WebControls_BaseDataList_DataSource这是 MSDN 文章的链接: https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.basedatalist.datasource?view=netframework-4.8#System_Web_UI_WebDataControls_BaseDataSource

What is your data source?你的数据源是什么? Are you using a database?你在使用数据库吗?

If you do not have a database you can mockup a dataset in XML, JSON, or CSV and then deserialize into your code.如果您没有数据库,您可以在 XML、JSON 或 CSV 中模拟数据集,然后反序列化到您的代码中。

I believe that you can bind anything that implements IList .我相信你可以绑定任何实现IList的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM