asp.net中repeater簡單的分頁 asp.net里面的Repeater控件怎么做分頁功能。
第一,把前臺頁面寫好,例如
<td colspan="2" style="font-size:12pt;color:#0099ff; background-color:#e6feda;">
共<asp:Label ID="lblpc" runat="server" Text="Label"></asp:Label>頁 當前為第
<asp:Label ID="lblp" runat="server" Text="Label"></asp:Label>頁
<asp:HyperLink ID="hlfir" runat="server" Text="首頁"></asp:HyperLink>
<asp:HyperLink ID="hlp" runat="server" Text="上一頁"></asp:HyperLink>
<asp:HyperLink ID="hln" runat="server" Text="下一頁"></asp:HyperLink>
<asp:HyperLink ID="hlla" runat="server" Text="尾頁"></asp:HyperLink>
跳至第
<asp:DropDownList ID="ddlp" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlp_SelectedIndexChanged" >
</asp:DropDownList>頁
</td>
第二、在后臺實現(xiàn)分頁
private PagedDataSource pds()
{
string connstring = ConfigurationManager.ConnectionStrings["pconn"].ConnectionString;
SqlConnection con = new SqlConnection(connstring);
DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter("select * from authors",con);
sda.Fill(ds,"name");
SqlDataAdapter sda2 = new SqlDataAdapter("select * from titleauthor",con);
sda2.Fill(ds,"title");
ds.Relations.Add("myrela",ds.Tables["name"].Columns["au_id"],ds.Tables["title"].Columns["au_id"]);
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables["name"].DefaultView;
pds.AllowPaging = true;//允許分頁
pds.PageSize = 5;//單頁顯示項數(shù)
pds.CurrentPageIndex = Convert.ToInt32(Request.QueryString["page"]);
return pds;
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Footer)
{
DropDownList ddlp = (DropDownList)e.Item.FindControl("ddlp");
HyperLink lpfirst = (HyperLink)e.Item.FindControl("hlfir");
HyperLink lpprev = (HyperLink)e.Item.FindControl("hlp");
HyperLink lpnext = (HyperLink)e.Item.FindControl("hln");
HyperLink lplast = (HyperLink)e.Item.FindControl("hlla");
pds().CurrentPageIndex = ddlp.SelectedIndex;
int n = Convert.ToInt32(pds().PageCount);//n為分頁數(shù)
int i = Convert.ToInt32(pds().CurrentPageIndex);//i為當前頁
Label lblpc = (Label)e.Item.FindControl("lblpc");
lblpc.Text = n.ToString();
Label lblp = (Label)e.Item.FindControl("lblp");
lblp.Text = Convert.ToString(pds().CurrentPageIndex + 1);
if (!IsPostBack)
{
for (int j = 0; j < n; j++)
{
ddlp.Items.Add(Convert.ToString(j + 1));
}
}
if (i <= 0)
{
lpfirst.Enabled = false;
lpprev.Enabled = false;
lplast.Enabled = true;
lpnext.Enabled = true;
}
else
{
lpprev.NavigateUrl = "?page=" + (i - 1);
}
if (i >= n - 1)
{
lpfirst.Enabled = true;
lplast.Enabled = false;
lpnext.Enabled = false;
lpprev.Enabled = true;
}
else
{
lpnext.NavigateUrl = "?page=" + (i + 1);
}
lpfirst.NavigateUrl = "?page=0";//向本頁傳遞參數(shù)page
lplast.NavigateUrl = "?page=" + (n - 1);
ddlp.SelectedIndex = Convert.ToInt32(pds().CurrentPageIndex);//更新下拉列表框中的當前選中頁序號
}
}
protected void ddlp_SelectedIndexChanged(object sender, EventArgs e)
{//腳模板中的下拉列表框更改時激發(fā)
string pg=Convert.ToString((Convert.ToInt32(((DropDownList)sender).SelectedValue)-1));//獲取列表框當前選中項
Response.Redirect("repeate.aspx?page="+pg);//頁面轉(zhuǎn)向
}
}
可能比較亂,麻煩您請看 http://blog.csdn.net/qin_zhangyongheng/article/details/7823192
電子商務(wù)網(wǎng)站一般架構(gòu)有哪些
當然也可以設(shè)計得更簡單的一些。靜態(tài)的頁面建議使用CDN加速,以解決網(wǎng)通和電信之間訪問速度的問題; 數(shù)據(jù)的緩存方面建議考慮用memcache,另外也可以分別在表現(xiàn)層和數(shù)據(jù)層利用.net中的現(xiàn)存緩存機制作業(yè)可; 簡單執(zhí)行的sql可以不用存儲過程,存儲過程會占用數(shù)據(jù)庫服務(wù)器的處理時間,造成死鎖; mvc建議還是做些CMS的項目上應(yīng)用,電...
高中人教版語文課文的范讀 mp3的
(均為RM,格式)此網(wǎng)站似乎提到了MP3格式的英語材料可是瀏覽中并未發(fā)現(xiàn)。4. http:\/\/www.crazyenglish.org\/dwncenter.asp瘋狂英語的語音下載中心,有許多很不錯的關(guān)于瘋狂英語和鐘道隆的逆向英語的有聲材料(RM格式)5. http:\/\/www.englishlover.net\/在其在線聽力里面有部分對話(RM格式)。6. http:\/\/zflyingbird.my...
電子商務(wù)網(wǎng)站一般架構(gòu)有哪些
當然也可以設(shè)計得更簡單的一些。 靜態(tài)的頁面建議使用CDN加速,以解決網(wǎng)通和電信之間訪問速度的問題;數(shù)據(jù)的緩存方面建議考慮用memcache,另外也可以分別在表現(xiàn)層和數(shù)據(jù)層利用.net中的現(xiàn)存緩存機制作業(yè)可;簡單執(zhí)行的sql可以不用存儲過程,存儲過程會占用數(shù)據(jù)庫服務(wù)器的處理時間,造成死鎖;mvc建議還是做些CMS的項目上應(yīng)用,電子...
相關(guān)評說:
靖安縣總重: ______ repeater里面建立模板列,然后在模板列里隨心所欲的搞吧,repeater很靈活,適合自定義的表格嵌套~~ 用的好不比DATAGRID差,就是很多屬性需要手工添加,不如DG來的方便~~ 去問度娘,現(xiàn)在網(wǎng)絡(luò)這么發(fā)達,自己動手搜~
靖安縣總重: ______ 1,要分組查詢 2,做個方法判斷是否是同一種習慣,如果是累加td rowspan= 重復(fù)出現(xiàn)的個數(shù) 以后再重復(fù)出現(xiàn)把td去掉 3,看你單選按鈕的內(nèi)容是如何存的 以-為列子,做一個方法根據(jù)'-'分割成string數(shù)組,在遍歷添加到單選按鈕的集合了,當然組名要不一樣 好了準備工作完成了,其他就是動態(tài)的綁定 ,調(diào)用方法了,
靖安縣總重: ______ 在這里可以設(shè)定一個隱藏的標記0/1,當是從數(shù)據(jù)庫中讀出來的數(shù)據(jù),在綁定的時候給隱藏的標記賦為1,然后在BUTTON的事件中,去根據(jù)這個標記的值來進行相關(guān)的操作,是UPDATE,還是INSERT就自由決定了.
靖安縣總重: ______ Repeater 跟其他綁定控件類似,比如DataList 但是不能像那些控件一樣可視編輯模板.而必須在前臺代碼頁內(nèi)編輯模板.在代碼<Repeater></Repeater> 中輸入<會自動提示常用的就是HeaderTemplate設(shè)置標題模板,ItemTemplate 設(shè)置內(nèi)容模板...
靖安縣總重: ______ Repeater的分頁和datalist的一樣,你可以使用分頁控件就OK了,比如ASPNetPager,webpager...分頁控件就可以實現(xiàn)
靖安縣總重: ______ <asp:Repeater ID="rpt1" runat="server"> <ItemTemplate><tr onmouseout="this.style.backgroundColor=c" onmouseover="c=this.style.backgroundColor;this.style.backgroundColor='#f4f4f4'"> <td><%#"<a href='FamilyLedger_Add.aspx?...
靖安縣總重: ______ datalist被服務(wù)器解析出來的會是一段table代碼,table代碼里有很多垃圾代碼呢. 而repeater正是順應(yīng)了div+css布局的要求,它是沒任何垃圾代碼的,而且很輕便,相對于datalist.
靖安縣總重: ______ Repeater,用二表示層綁定數(shù)據(jù)的. 如:表示層 <%#Eval("這里為數(shù)據(jù)庫字段名")%> 后代碼: dr為sqldataredeaer對象 this.Repeater1.DataSource = dr; this.Repeater1.DataBind();
靖安縣總重: ______ 用TABLE就可以了. 在頭模板加一個<TABLE> 項模板就加<tr><td>內(nèi)容</td><td>內(nèi)容</td><td>內(nèi)容</td><tr> 在腳模板加一個</TR></TABLE>