VS2005中GridView的自定义分页,单选、多选、排序、自增列的简单应用_第1页
VS2005中GridView的自定义分页,单选、多选、排序、自增列的简单应用_第2页
VS2005中GridView的自定义分页,单选、多选、排序、自增列的简单应用_第3页
VS2005中GridView的自定义分页,单选、多选、排序、自增列的简单应用_第4页
VS2005中GridView的自定义分页,单选、多选、排序、自增列的简单应用_第5页
已阅读5页,还剩11页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、关于VS2005中GridView 的自定义分页,单选、多选、排序、自增列的简单应用多选时,只有全部选中时多选”才选中。图片效果:简单示例,代码如下,fenpage.aspx 的代码:ULJ! DOCTYPE html PUBLIC -/W3C/DTD XHTML 1.0 Transitional/EN HYPERLINK http:/w http:/w /TR/xhtml1/DTD/xhtml1-transitional.dtdHE/判断多选是否与选中项(没有选中的返回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 函/只有全部选中时全选”选中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 =价格FooterText=价格DataField =price DataFormatString =0: #,#0.00HtmlEncode=False SortExpression =price /asp:BoundField HeaderText =数字FooterText =数字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/计算生成分页页码,分别为:首 页上一页下一页尾 页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(数据库错误,错误原因:+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(处理后存放在数组中,如下: );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);数据库中表的生成代码: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等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论