VS2005中GridView的自定義分頁,單選、多選、排序、自增列的簡單應(yīng)用_第1頁
VS2005中GridView的自定義分頁,單選、多選、排序、自增列的簡單應(yīng)用_第2頁
VS2005中GridView的自定義分頁,單選、多選、排序、自增列的簡單應(yīng)用_第3頁
VS2005中GridView的自定義分頁,單選、多選、排序、自增列的簡單應(yīng)用_第4頁
VS2005中GridView的自定義分頁,單選、多選、排序、自增列的簡單應(yīng)用_第5頁
已閱讀5頁,還剩11頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、關(guān)于VS2005中GridView 的自定義分頁,單選、多選、排序、自增列的簡單應(yīng)用多選時(shí),只有全部選中時(shí)多選”才選中。圖片效果:簡單示例,代碼如下,fenpage.aspx 的代碼:ULJ! DOCTYPE html PUBLIC -/W3C/DTD XHTML 1.0 Transitional/EN HYPERLINK http:/w http:/w /TR/xhtml1/DTD/xhtml1-transitional.dtdHE/判斷多選是否與選中項(xiàng)(沒有選中的返回false )function slcNo_click()if(document.form1.checkboxname.le

2、ngth)百由for(var i=0;i1)口口Ifor (var i=0;idocument.all.checkboxname.length;i+)口口 Idocument.all.checkboxnamei.checked = boolvalue;IelseIdocument.all.checkboxname.checked = boolvalue;rri/IL 顯 田田 1 箴1 函/只有全部選中時(shí)全選”選中function SingleCheckJs()var flag1= false ;var flag2= false ;if (document.form1.checkboxname

3、.length)for (var i=0;idocument.form1.checkboxname.length;i+)if (document.form1.checkboxnamei.checked)flag1 =true ;elseflag2 =true ;else白白Iif (document.forml.checkboxname.checked)Iflagl=true;IelseIflag2=true;TIif (flag1= true &flag2= false )Idocument.getElementById(chk).checked=IelseIdocument.getElem

4、entById(chk).checked=/L_I-I一L asp:TemplateFieldHeaderText=全選FooterText =全選 input type =checkboxid =checkboxnamename=checkboxnamevalue =/ ItemTemplate/ asp:TemplateField asp:TemplateFieldHeaderText =單選FooterText=單選 ItemTemplate input type=radio id =RadioName name=RadioName value = / ItemTemplate/ asp

5、:TemplateField asp:TemplateFieldHeaderText =自增歹U FooterText =自增列 ItemTemplate/ ItemTemplate/ asp:TemplateFieldasp:BoundField HeaderText =價(jià)格FooterText=價(jià)格DataField =price DataFormatString =0: #,#0.00HtmlEncode=False SortExpression =price /asp:BoundField HeaderText =數(shù)字FooterText =數(shù)字D ataField =price Da

6、taFormatString =0:0.00HtmlEncode=False SortExpression =price / TOC o 1-5 h z |SelectedRowStyle BackColor =#E2DED6 Font-Bold =TrueForeColor =#333333/PagerStyle BackColor =#284775 ForeColor =White Horiz ontalAlign =Center /AlternatingRowStyle BackColor =White ForeColor =#284775 /PagerSettings Visible

7、=False /一HeaderStyle Font-Bold =False Font-Italic =False /一一一 首頁 上一頁 下一頁 尾頁ll asp:Label asp:Label asp:Label/ asp:Button/asp:Buttonfenpage.aspx.cs 的代碼:using System;using System.Data;runat =serverasp:LabeText =checkbox得至 UText =radio得到選擇using System.Configuration;using System.Collections;using System.

8、Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.Data.SqlClient;public partial class gridview_fenpage : System.Web.UI.PageUUprotected void Page_Load( object sender, EventArgs e)自力B

9、utton2.Attributesonclick = return slcNo_click();I GridViewBind();LI private void GridViewBind( string Sqlsort)I string connStr = ConfigurationManager.ConnectionStringsConnString1.ConnectionString;I string SqlStr = SELECT * FROM test01 where id1000 + Sqlsort;I DataSet ds = new DataSet();I-Itry口口 I Sq

10、lConnection conn =new SqlConnection(connStr);Iif (conn.State.ToString() = Closed) conn.Open();SqlDataAdapter da =new SqlDataAdapter(SqlStr, conn);da.Fill(ds, test01);if (conn.State.ToString() = Open) conn.Close();GridViewl.DataSource = ds.Tables0.DefaultView;GridView1.DataBind();LblCurrentIndex.Text

11、 =第+ (GridView1.PageIndex + 1).ToString()+ 頁”;LblPageCount.Text =共+ GridViewl .PageCount.ToString()+ 頁”;LblRecordCount.Text =總共+ds.Tables0.Rows.Count.ToString()+條;if (ds.Tables0.Rows.Count = 0)btnFirst.Visible =false ;btnPrev.Visible =false ;btnNext.Visible =false ;btnLast.Visible =false ;false ;Lbl

12、Currentlndex.Visible =LblPageCount.Visible =false ;LblRecordCount.Visible =false ;else if (GridViewl.PageCount = 1)IbtnFirst.Visible =false1btnPrev.Visible =false1btnNext.Visible =falseTbtnLast.Visible =falseI/計(jì)算生成分頁頁碼,分別為:首 頁上一頁下一頁尾 頁I btnFirst.CommandName = 1;I btnPrev.CommandName = (GridViewl.Pag

13、elndex = 0 ? 1 : GridView 1.PageIndex.ToString();I btnNext.CommandName = (GridViewl.PageCount = 1 ? GridViewl.Pa geCount.ToString() : (GridViewl.Pagelndex + 2).ToString();I btnLast.CommandName = GridView1.PageCount.ToString();I /Icatch (Exception ex)口口 IIResponse.Write(數(shù)據(jù)庫錯(cuò)誤,錯(cuò)誤原因:+ex.Message);IRespo

14、nse.End();I protected void PagerButtonClick( object sender, EventArgs e) 自己IGridView1.PageIndex = Convert.ToInt32(LinkButton)sender).CommandName)-1;IGridViewBind();Tprotected void GridView1_RowDataBound( object sender, GridViewRowEventA rgs e)口口 I e.Row.Attributesonmouseover = ItemOver(this);protect

15、edvoid Button2_Click( object sender, EventArgs e)stringstr=;string口ckb=null ;str=Request.Form.Get(checkboxname);白白ckb=str.Split(new char 口,);Response.Write(直接在頁面中得到的值為:+str+);Response.Write(處理后存放在數(shù)組中,如下: );for (int i=0;ickb.Length;i+)Response.Write(ckb+i+的值為:+ckbi+);protected void Button1_Click(obje

16、ct sender, EventArgs e)Response.Write(Request.Form.Get(RadioName);protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)string sql =;if (ViewStateSortDirection=null | ViewStateSortDirection.ToString().CompareTo() = 0)百由ViewStateSortDirection = desc;elseViewStateSortDirection=;sql = order by + e.SortExpression + ViewStateSortDirection;GridViewBind(sql);數(shù)據(jù)庫中表的生成代碼:CREATE TABLE dbo .test01(id decimal (18 , 0) IDENTITY (1,1) NOT NULL ,name varchar (50) COLLATE C

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論