如何在Repeater中显示x项,并使用asp.net滚动或淡出下一个项
本文关键字:asp net 滚动 下一个 淡出 Repeater 显示 | 更新日期: 2023-09-27 18:09:54
我有一个在从数据库显示的主页上显示'新闻'的中继器。我想一次只显示2条记录,并在滚动或淡出效果的某些毫秒后自动滚动下两个项目。
<asp:Repeater ID="RepDetails" runat="server" OnItemDataBound="RepDetails_ItemDataBound">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<div id="MainContent" style="border: 1px;">
<table>
<tr>
<td rowspan="2" class="auto-style2">
<img src="Images/lasts1.png" />
</td>
<td>
<asp:Label ID="lblNewsTitle" runat="server" Font-Bold="True" /></td>
<td> </td>
</tr>
<tr width="100px">
<td>
<asp:Label ID="lblNewsDescription" runat="server" /></td>
<td> </td>
</tr>
</table>
</div>
<hr />
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater>
.cs Page:
protected void RepDetails_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DataRowView dr = e.Item.DataItem as DataRowView;
string Id = Convert.ToString(dr["NewsID"]);
//HtmlGenericControl teammemberapp = e.Item.FindControl("teammemberapp") as HtmlGenericControl;
//Link to TeamMemberDetails Page
//teammemberapp.Attributes.Add("onclick", "window.location.href='NewsDetails.aspx?Id=" + Id + "'");
string newsTitle = Convert.ToString(dr["NewsTitle"]);
Label lblNewsDescription = e.Item.FindControl("lblNewsDescription") as Label;
Label lblNewsTitle = e.Item.FindControl("lblNewsTitle") as Label;
//set First Name Label
lblNewsTitle.Text = newsTitle;
string newsDescription = Convert.ToString(dr["NewsDescription"]);
if (newsDescription.Length > 50)
{
lblNewsDescription.Text = newsDescription.Substring(0, 50) + "..";
}
else
{
lblNewsDescription.Text = newsDescription;
}
}
}
public void GetRecord()
{
string connectionString = ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString.ToString();
DataTable datatable = new DataTable();
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = connection;
connection.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "usp_NewsSelectYES";
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(datatable);
connection.Close();
}
//Bind Table to Repeater
RepDetails.DataSource = datatable;
RepDetails.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//Get all news with yes
GetRecord();
}
}
帮助感激!谢谢!
尝试使用一些jquery滑块