我怎么能显示前3名的记录

时间:2017-03-07 07:49:36

标签: asp.net vb.net entity-framework repeater

我在ASP.NET网站上有一个转发器,我想只显示3条记录 中继器:

window.onload = function () {
    var fileUpload = document.getElementById("fileupload");
    fileUpload.onchange = function () {
        if (typeof (FileReader) != "undefined") {
            var dvPreview = document.getElementById("dvPreview");
            dvPreview.innerHTML = "";
            var regex = /^([a-zA-Z0-9\s_\\.\-:])+(.jpg|.jpeg|.gif|.png|.bmp)$/;
            for (var i = 0; i < fileUpload.files.length; i++) {
                var file = fileUpload.files[i];
                if (regex.test(file.name.toLowerCase())) {
                    var reader = new FileReader();
                    reader.onload = function (e) {
                        var img = document.createElement("IMG");
                        var textbox = document.createElement('input');
                        textbox.type = 'text';
                        textbox.name = 'tag_line[]';
                        textbox.placeholder = 'Enter image tag line';
                        img.height = "100";
                        img.width = "100";
                        img.src = e.target.result;
                        dvPreview.appendChild(img);
                        dvPreview.appendChild(textbox);
                    }
                    reader.readAsDataURL(file);
                } else {
                    alert(file.name + " is not a valid image file.");
                    dvPreview.innerHTML = "";
                    return false;
                }
            }
        } else {
            alert("This browser does not support HTML5 FileReader.");
        }
    }
};



<div class="row">
<div class="form-group col-sm-6">
<input id="fileupload" type="file" multiple="multiple" />
<hr />
<b>Preview</b><br />
</div>
</div>
<div id="dvPreview">
</div>

和实体模型

<asp:Repeater ID="repNews" runat="server" DataSourceID="EntityDataSource1">
    <ItemTemplate>
        <ul>
         <li><a href='<%# Eval("news_link")%>' > <asp:Label ID="lblNews" runat="server" Text='<%# Eval("news_title")%>' /></a></li> 
      </ul>
    </ItemTemplate>

1 个答案:

答案 0 :(得分:1)

谢谢你们,但我尝试了这个和这项工作

Select="top(2) it.news_title,it.news_link"

将其添加到entitydatasoruce

就像这样

<asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=AGIP_dbEntities" DefaultContainerName="AGIP_dbEntities" EnableFlattening="False" EntitySetName="tbl_news"  Select="top(2) it.news_title,it.news_link">
  </asp:EntityDataSource>