来自 asp.net 中数据库的选取框
Marquee from database in asp.net
首先,我使用带中继器的选框,它工作正常,但它同时显示所有数据。
我的代码如下所示:
<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>
下面是我的代码隐藏页面:
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();
}
}
我想一个一个地显示数据,我该怎么做?
提前谢谢你,
您可以检查的内容很少
Repeater 控件没有水平或垂直"direction"。您要么需要通过 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 服务器,那么您可以使用 getdate() 函数
where visibility=1 and FromDate >= getdate()
要仅获取日期,您可以使用 Convert(date, getdate()),有关详细信息,请参阅您的数据库的文档。
首先,我使用带中继器的选框,它工作正常,但它同时显示所有数据。
我的代码如下所示:
<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>
下面是我的代码隐藏页面:
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();
}
}
我想一个一个地显示数据,我该怎么做?
提前谢谢你,
您可以检查的内容很少
Repeater 控件没有水平或垂直"direction"。您要么需要通过 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 服务器,那么您可以使用 getdate() 函数
where visibility=1 and FromDate >= getdate()
要仅获取日期,您可以使用 Convert(date, getdate()),有关详细信息,请参阅您的数据库的文档。