来自asp.net数据库的Marquee

时间:2015-02-24 12:39:03

标签: c# asp.net repeater marquee

首先,我使用带有转发器的字幕,它工作正常,但它同时显示所有数据。

我的代码如下:



<marquee id="ml" style="text-align: center" width="400px" height="170"
               scrolldelay="5" scrollamount="5">
    <asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate>
            <br />
            <asp:Label ID="Label1" runat="server" Text='<%# Eval("notification") %>'></asp:Label><br />
        </ItemTemplate>
    </asp:Repeater>
</marquee>
&#13;
&#13;
&#13;

以下是我的代码隐藏页面:

&#13;
&#13;
private void getnotification()
{
        DataTable notifydt = new DataTable();
        DateTime currentdt = DateTime.Now;
        string date1 = currentdt.ToString("yyyy-MM-dd");
        string qry = "";
        qry = "select notification from adminnotification where visibility=1 and FromDate >='" + date1 + "'";
        SqlDataAdapter sda = new SqlDataAdapter(qry, con);
        StringBuilder sb = new StringBuilder();
        
        con.Open();
        sda.Fill(notifydt);
        int count = notifydt.Rows.Count;

        DataView dv = new DataView(notifydt);

        if (count > 0)
        {
            foreach (DataRow DR in notifydt.Rows)
            {
                dv.RowFilter = "notification='" + DR["Notification"].ToString()+ "'";
            }
           
            Repeater1.DataSource = dv;
            Repeater1.DataBind();
        }
    }
&#13;
&#13;
&#13;

我想逐个显示数据,我该怎么做?

提前谢谢你,

1 个答案:

答案 0 :(得分:0)

您可以检查的内容很少

  • Repeater控件没有水平或垂直“方向”。你需要通过css控制它:

    <ItemTemplate>
    <div style="float:left">
        <asp:Label ID="Label1" runat="server" Text='<%# Eval("notification") %>' />
    </div>
    </ItemTemplate>
    

    或使用其他控件,如DataList,您可以在其中设置方向

    <asp:DataList RepeatDirection="Horizontal" ... > 
    
  • 以下过滤器没有意义,需要删除

    foreach (DataRow DR in notifydt.Rows)
    {
        dv.RowFilter = "notification='" + DR["Notification"].ToString()+ "'";
    }
    
  • 可以直接在sql中设置按日期过滤。例如,如果您使用SQL Server,则可以使用getdate()函数

    where visibility=1 and FromDate >= getdate()
    

    要获得只能使用Convert(date,getdate())的日期,请参阅数据库的文档以获取更多详细信息。