webform 網站 相關 數據 控件 其餘 欄目 網站開發 简体版
原文   原文鏈接

1、asp:Repeaterjavascript

  <div class="bd">
            <ul>
                <asp:Repeater ID="rept_slide" runat="server">
                    <ItemTemplate>
                        <li><a href='<%#Eval("LinkUrl").ToString() %>' target="_blank" style="background: url(images/<%#Eval("ImgUrl").ToString() %>) center 0 no-repeat;" ></a></li>
                    </ItemTemplate>
                </asp:Repeater>
            </ul>
        </div>

Repeater 控件用於顯示重複的項目列表css

後臺綁定數據:java

            DataTable dt = tbSlideFill();
            this.rept_slide.DataSource = dt.DefaultView;
            this.rept_slide.DataBind();

2、asp:Literaljquery

向頁面動態添加內容ide

<asp:Literal ID="lit_page" runat="server"></asp:Literal>
 this.lit_page.Text = Common.PageNums.GetPageNum(ds, rept_new, 2, "About.aspx?id=52", "Pager_blue");  //輸出分頁
          /// /// DataSet實例
        /// /// DataList名稱
        /// /// 分頁大小
        /// ///動態分頁
        public static string GetPageNum(DataSet ds, Repeater datalistname, int pagesize, string lurl, string classStr)
        {
            string pagestr = "";
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                PagedDataSource objPds = new PagedDataSource();
                objPds.DataSource = ds.Tables[0].DefaultView;
                objPds.AllowPaging = true;
                int total = ds.Tables[0].Rows.Count;
                objPds.PageSize = pagesize;
                int page;
                if (HttpContext.Current.Request.QueryString["page"] != null)
                    page = Convert.ToInt32(HttpContext.Current.Request.QueryString["page"]);
                else
                    page = 1;
                objPds.CurrentPageIndex = page - 1;
                datalistname.DataSource = objPds;
                datalistname.DataBind();
                int allpage = 0;
                int next = 0;
                int pre = 0;
                int startcount = 0;
                int endcount = 0;

                if (page < 1)
                {
                    page = 1;
                }
                //計算總頁數
                if (pagesize != 0)
                {
                    allpage = (total / pagesize);
                    allpage = ((total % pagesize) != 0 ? allpage + 1 : allpage);
                    allpage = (allpage == 0 ? 1 : allpage);
                }
                next = page + 1;
                pre = page - 1;
                startcount = (page + 5) > allpage ? allpage - 7 : page - 4;//中間頁起始序號
                endcount = page < 5 ? 8 : page + 5;//中間頁終止序號 
                if (startcount < 1)
                { startcount = 1; }
                //爲了不輸出的時候產生負數,設置若是小於1就從序號1開始
                if (allpage < endcount)
                {
                    endcount = allpage;
                }
                //頁碼+5的可能性就會產生最終輸出序號大於總頁碼,那麼就要將其控制在頁碼數以內 
                pagestr = "<div class='" + classStr + "'>";
                pagestr += page > 1 ? "<a href='" + lurl + "&page=1' class=\"homePage\">首頁</a><a href='" + lurl + "&page=" + pre + "' class=\"prevPage\">上一頁</a>" : "<a href='" + lurl + "&page=1' class=\"homePage\">首頁</a>";
             for (int i = startcount; i <= endcount; i++)
                {
                   pagestr += page == i ? "<a href=\"javascript:;\" class=\"on\">" + i + "</a>" : "  " + "<a href='" + lurl + "&page=" + i + "'>" + i + "</a>" + " ";
                }
                 pagestr += page != allpage ? "<a href='" + lurl + "&page=" + next + "'  class=\"nextPage\">下一頁</a><a href='" + lurl + "&page=" + allpage + "' class=\"endPage\">末頁</a>" : "<a href=\"javascript:;\"  class=\"endPage\">末頁</a>";
                pagestr += "</div>";
            }
            else
            {
                pagestr = "暫無數據";
            }
            return pagestr;
        }
View Code

3、asp:DataList
DataList 控件,相似於 Repeater 控件,用於顯示綁定在該控件上的項目的重複列表。不過,DataList 控件會默認地在數據項目上添加表格。this

             <asp:DataList ID="DataInfo" runat="server" OnItemCommand="DataInfo_ItemCommand" DataKeyField="InfoId">
                            <HeaderTemplate>
                                <table cellpadding="0" cellspacing="0" border="1" width="900" class="tablecss">
                                    <tr>
                                        <td width="50" align="center">序號</td>
                                        <td width="30" align="center">選擇</td>
                                        <td width="500" align="ceter">標題</td>
                                        <td width="50" style="text-align:center;">排序號</td>
                                        <td style="text-align:center;">操做</td>
                                    </tr>
                                </table>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <table cellpadding="0" cellspacing="0" border="1" width="900" class="tablecss2">
                                    <tr>
                                        <td width="50" align="center"><%#(Container.ItemIndex+1).ToString() %></td>
                                        <td width="30" align="center"><asp:CheckBox ID="CheckBox1" runat="server" /></td>
                                        <td width="500" align="center"><%#DataBinder.Eval(Container.DataItem,"Title") %></td>
                                        <td width="50" align="center"><asp:TextBox ID="txsort" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Sort") %>' Columns="2"></asp:TextBox></td>
                                        <td style="text-align:center;">
                                            <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false" CommandName="edit" Text="修改"></asp:LinkButton>
                                            <asp:LinkButton ID="LinkButton5" runat="server" CausesValidation="false" CommandName="Delete" Text="刪除" OnClientClick="return confirm('確認要刪除嗎?')"></asp:LinkButton>
                                        </td>
                                    </tr>
                                </table>
                            </ItemTemplate>
                        </asp:DataList>
View Code
            this.DataInfo.DataSource = objpbs;
            this.DataInfo.DataBind();

4、分頁url

一、先引用AspNetPager.dllspa

二、在頁面上加上一句:<%@ Register TagPrefix="Webdiyer" Namespace="Wuqi.Webdiyer" Assembly="aspnetpager" %>code

三、server

                  <Webdiyer:AspNetPager runat="server" ID="pager" AlwaysShow="true" HorizontalAlign="Left" ShowInputBox="Always"
                             ShowPageIndex="false" FirstPageText="首頁" LastPageText="末頁" PrevPageText="上頁" NextPageText="下頁"
                             Width="100%" ShowCustomInfoSection="Left" TextBeforeInputBox="轉到轉到第&nbsp;" TextAfterInputBox="&nbsp;頁&nbsp;"
                             PageSize="15" OnPageChanged="pager_PageChanged"/>

四、後臺綁定數據

            DataTable dt=tbInfoFill();
            pager.RecordCount = dt.Rows.Count;
            PagedDataSource objpbs = new PagedDataSource();
            objpbs.DataSource = dt.DefaultView;
            objpbs.AllowPaging = true;
            objpbs.PageSize = pager.PageSize;
            objpbs.CurrentPageIndex = pager.CurrentPageIndex - 1;

5、其餘

一、幻燈片展現

a、引入js文件:<script src="js/jquery.SuperSlide.2.1.1.js" type="text/javascript"></script>

b、

  <div class="banner">
        <div class="bd">
            <ul>
                <asp:Repeater ID="rept_slide" runat="server">
                    <ItemTemplate>
                        <li><a href='<%#Eval("LinkUrl").ToString() %>' target="_blank" style="background: url(images/<%#Eval("ImgUrl").ToString() %>) center 0 no-repeat;" ></a></li>
                    </ItemTemplate>
                </asp:Repeater>
            </ul>
        </div>

    </div>
    <script type="text/javascript">
        jQuery(".banner").slide({ mainCell: ".bd ul", autoPlay: true });
    </script>

二、marquee
a、建立一個滾動的文本字幕

<marquee  direction="up" behavior="scroll" scrollamount="5"  onMouseOut="this.start()" onMouseOver="this.stop()" >
     <span class="fl"><a href='NewInfo.aspx?id=<%#Eval("InfoId").ToString() %>'><%#Eval("Title").ToString() %></a></span>
      <span class="time fr"><%#Eval("AppDate","{0:yyyy-MM-dd}").ToString() %></span>
</marquee>

direction:表示滾動的方向
behavior:表示滾動的方式

scrollamount:表示文字滾動的速度

onMouseOut:表示當鼠標移上去滾動中止

onMouseOver:表示當鼠標移開滾動開始

b、用js來實現

 <script type="text/javascript">
        var speed = 80
        function Marquee() {
                demo.scrollTop++;
                if (demo.scrollTop > "27")
                {
                    demo.scrollTop = "0";
                }
        }
        var MyMar = setInterval(Marquee, speed)
        demo.onmouseover = function () { clearInterval(MyMar) }
        demo.onmouseout = function () { MyMar = setInterval(Marquee, speed) }
</script>
相關文章
相關標籤/搜索
每日一句
    每一个你不满意的现在,都有一个你没有努力的曾经。
本站公眾號
   歡迎關注本站公眾號,獲取更多信息