简体   繁体   中英

How to show x-items in Repeater and scroll or fadein-fadeout next items using asp.net?

I have a repeater which displays 'News' on home page which is diplayed from database. I want to display just 2records at a time and automatically scrolling next two items after certain milliseconds with scrolling or fadein-fadeout effect.

In aspx page:

<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>&nbsp;</td>
                    </tr>
                    <tr width="100px">
                        <td>
                            <asp:Label ID="lblNewsDescription" runat="server" /></td>
                        <td>&nbsp;</td>
                    </tr>
                </table>

            </div>
            <hr />
        </ItemTemplate>
        <FooterTemplate>
        </FooterTemplate>
    </asp:Repeater>

In .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();

                }
            }

Help Appreciated! Thanks!

尝试使用某种jQuery滑块

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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