实现自定义分页(如:改变传统datagrid的分页显示、通过A-Z的字母来分页等)、选择的check...

function StorePage() { d=document; t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():''); void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes')); keyit.focus(); }

代码
 
   
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace DataGridDemoCS { /// /// Demo1 的摘要说明。 /// public class DemoFinal : System.Web.UI.Page { protected System.Data.SqlClient.SqlConnection sqlConnection1; protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1; // 注意:dataset在编辑状态中将清空,所以可以将dataset申明为static,这样就可以保持dataset状态; // 静态成员变量不可以用this来调用 protected DataGridDemoCS.dsCustomers dsCustomers1; protected DataGridDemoCS.dsCustomers.CustomersDataTable dsCustomerTable; protected DataGridDemoCS.dsCustomers.CustomersRow dsCustomerRow; protected System.Data.SqlClient.SqlCommand sqlSelectCommand1; protected System.Data.SqlClient.SqlCommand sqlInsertCommand1; protected System.Data.SqlClient.SqlCommand sqlUpdateCommand1; protected System.Data.SqlClient.SqlCommand sqlDeleteCommand1; protected System.Data.SqlClient.SqlConnection sqlConnection2; protected System.Web.UI.WebControls.Button Button1; protected System.Web.UI.WebControls.Button BtnInsertOneRow; protected System.Web.UI.WebControls.Button BtnDeleteGrouply; protected System.Web.UI.WebControls.Panel PnlPage; protected System.Data.DataView dv; protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter2; protected System.Data.SqlClient.SqlConnection sqlConnection3; protected System.Web.UI.WebControls.DataGrid DataGrid1; public int ExpandedItem = 7 ; public Unit HostColumnWidth; private DataGrid detailsGrid; const string ExpandText = " + " ; protected System.Data.SqlClient.SqlCommand sqlSelectCommand2; protected System.Data.SqlClient.SqlCommand sqlInsertCommand2; protected System.Data.SqlClient.SqlCommand sqlUpdateCommand2; protected System.Data.SqlClient.SqlCommand sqlDeleteCommand2; protected System.Web.UI.WebControls.Button Button2; const string CollapseText = " - " ; private void Page_Load( object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 if ( ! Page.IsPostBack) { ExpandedItem = - 1 ; testWorkFlow = "" ; ViewState[ " Sort " ] = " CustomerID " ; ViewState[ " orderby " ] = " asc " ; bindDate(); BtnDeleteGrouply.Attributes.Add( " OnClick " , " javascript:DeleteGrouply(); " ); HostColumnWidth = Unit.Pixel( 150 ); } } void bindDate() { testWorkFlow = "" ; sqlDataAdapter1.Fill(dsCustomers1, " Customers " ); if (( string )(ViewState[ " Sort " ]) != "" ) dv.Sort = ( string )ViewState[ " Sort " ] + " " + ViewState[ " orderby " ]; else dsCustomers1.Customers.DefaultView.Sort = " CustomerID " ; if (( string )(ViewState[ " alpha " ]) != "" ) { dv.RowFilter = " CustomerID LIKE ' " + ( string )(ViewState[ " alpha " ]) + " %' " ; } DataGrid1.DataBind(); m_CreatePageTimes = 0 ; } #region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base .OnInit(e); } /// /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// private void InitializeComponent() { this .sqlConnection1 = new System.Data.SqlClient.SqlConnection(); this .sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter(); this .sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand(); this .sqlConnection2 = new System.Data.SqlClient.SqlConnection(); this .sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand(); this .sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand(); this .sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand(); this .dsCustomers1 = new DataGridDemoCS.dsCustomers(); this .dv = new System.Data.DataView(); this .sqlDataAdapter2 = new System.Data.SqlClient.SqlDataAdapter(); this .sqlDeleteCommand2 = new System.Data.SqlClient.SqlCommand(); this .sqlConnection3 = new System.Data.SqlClient.SqlConnection(); this .sqlInsertCommand2 = new System.Data.SqlClient.SqlCommand(); this .sqlSelectCommand2 = new System.Data.SqlClient.SqlCommand(); this .sqlUpdateCommand2 = new System.Data.SqlClient.SqlCommand(); ((System.ComponentModel.ISupportInitialize)( this .dsCustomers1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)( this .dv)).BeginInit(); this .DataGrid1.ItemCreated += new System.Web.UI.WebControls.DataGridItemEventHandler( this .DataGrid1_ItemCreated); this .DataGrid1.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler( this .DataGrid1_ItemCommand); this .DataGrid1.Init += new System.EventHandler( this .DataGrid1_Init); this .DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler( this .DataGrid1_PageIndexChanged); this .DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler( this .DataGrid1_CancelCommand); this .DataGrid1.PreRender += new System.EventHandler( this .DataGrid1_PreRender); this .DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler( this .DataGrid1_EditCommand); this .DataGrid1.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEventHandler( this .DataGrid1_SortCommand); this .DataGrid1.DataBinding += new System.EventHandler( this .DataGrid1_DataBinding); this .DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler( this .DataGrid1_UpdateCommand); this .DataGrid1.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler( this .DataGrid1_DeleteCommand); this .DataGrid1.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler( this .DataGrid1_ItemDataBound); this .Button1.Click += new System.EventHandler( this .Button1_Click); this .BtnInsertOneRow.Click += new System.EventHandler( this .BtnInsertOneRow_Click); this .BtnDeleteGrouply.Click += new System.EventHandler( this .BtnDeleteGrouply_Click); // // sqlConnection1 // this .sqlConnection1.ConnectionString = " workstation id=\"FANCY-FAMILY\";packet size=4096;user id=sa;data source=\"FANCY-FAMI " + " LY\";persist security info=False;initial catalog=Northwind " ; // // sqlDataAdapter1 // this .sqlDataAdapter1.DeleteCommand = this .sqlDeleteCommand1; this .sqlDataAdapter1.InsertCommand = this .sqlInsertCommand1; this .sqlDataAdapter1.SelectCommand = this .sqlSelectCommand1; this .sqlDataAdapter1.TableMappings.AddRange( new System.Data.Common.DataTableMapping[] { new System.Data.Common.DataTableMapping( " Table " , " Customers " , new System.Data.Common.DataColumnMapping[] { new System.Data.Common.DataColumnMapping( " CustomerID " , " CustomerID " ), new System.Data.Common.DataColumnMapping( " CompanyName " , " CompanyName " ), new System.Data.Common.DataColumnMapping( " ContactName " , " ContactName " ), new System.Data.Common.DataColumnMapping( " ContactTitle " , " ContactTitle " ), new System.Data.Common.DataColumnMapping( " Address " , " Address " ), new System.Data.Common.DataColumnMapping( " City " , " City " ), new System.Data.Common.DataColumnMapping( " Region " , " Region " ), new System.Data.Common.DataColumnMapping( " PostalCode " , " PostalCode " ), new System.Data.Common.DataColumnMapping( " Country " , " Country " ), new System.Data.Common.DataColumnMapping( " Phone " , " Phone " ), new System.Data.Common.DataColumnMapping( " Fax " , " Fax " )})}); this .sqlDataAdapter1.UpdateCommand = this .sqlUpdateCommand1; // // sqlDeleteCommand1 // this .sqlDeleteCommand1.CommandText = @" DELETE FROM Customers WHERE (CustomerID = @Original_CustomerID) AND (Address = @Original_Address OR @Original_Address IS NULL AND Address IS NULL) AND (City = @Original_City OR @Original_City IS NULL AND City IS NULL) AND (CompanyName = @Original_CompanyName) AND (ContactName = @Original_ContactName OR @Original_ContactName IS NULL AND ContactName IS NULL) AND (ContactTitle = @Original_ContactTitle OR @Original_ContactTitle IS NULL AND ContactTitle IS NULL) AND (Country = @Original_Country OR @Original_Country IS NULL AND Country IS NULL) AND (Fax = @Original_Fax OR @Original_Fax IS NULL AND Fax IS NULL) AND (Phone = @Original_Phone OR @Original_Phone IS NULL AND Phone IS NULL) AND (PostalCode = @Original_PostalCode OR @Original_PostalCode IS NULL AND PostalCode IS NULL) AND (Region = @Original_Region OR @Original_Region IS NULL AND Region IS NULL) " ; this .sqlDeleteCommand1.Connection = this .sqlConnection2; this .sqlDeleteCommand1.Parameters.Add( new System.Data.SqlClient.SqlParameter( " @Original_CustomerID " , System.Data.SqlDbType.NVarChar, 5 , System.Data.ParameterDirection.Input, false , ((System.Byte)( 0 )), ((System.Byte)( 0 )), " CustomerID " , System.Data.DataRowVersion.Original, null )); this .sqlDeleteCommand1.Parameters.Add( new System.Data.SqlClient.SqlParameter( " @Original_Address " , System.Data.SqlDbType.NVarChar, 60 , System.Data.ParameterDirection.Input, false , ((System.Byte)( 0 )), ((System.Byte)( 0 )), " Address " , System.Data.DataRowVersion.Original, null )); this .sqlDeleteCommand1.Parameters.Add( new System.Data.SqlClient.SqlParameter( " @Original_City " , System.Data.SqlDbType.NVarChar, 15 , System.Data.ParameterDirection.Input, false , ((System.Byte)( 0 )), ((System.Byte)( 0 )), " City " , System.Data.DataRowVersion.Original, null )); this .sqlDeleteCommand1.Parameters.Add( new System.Data.SqlClient.SqlParameter( " @Original_CompanyName " , System.Data.SqlDbType.NVarChar, 40 , System.Data.ParameterDirection.Input, false , ((System.Byte)( 0 )), ((System.Byte)( 0 )), " CompanyName " , System.Data.DataRowVersion.Original, null )); this .sqlDeleteCommand1.Parameters.Add( new System.Data.SqlClient.SqlParameter( " @Original_ContactName " , System.Data.SqlDbType.NVarChar, 30 , System.Data.ParameterDirection.Input, false , ((System.Byte)( 0 )), ((System.Byte)( 0 )), " ContactName " , System.Data.DataRowVersion.Original, null )); this .sqlDeleteCommand1.Parameters.Add( new System.Data.SqlClient.SqlParameter( " @Original_ContactTitle " , System.Data.SqlDbType.NVarChar, 30 , System.Data.ParameterDirection.Input, false , ((System.Byte)( 0 )), ((System.Byte)( 0 )), " ContactTitle " , System.Data.DataRowVersion.Original, null )); this .sqlDeleteCommand1.Parameters.Add( new System.Data.SqlClient.SqlParameter( " @Original_Country " , System.Data.SqlDbType.NVarChar, 15 , System.Data.ParameterDirection.Input, false , ((System.Byte)( 0 )), ((System.Byte)( 0 )), " Country " , System.Data.DataRowVersion.Original, null )); this .sqlDeleteCommand1.Parameters.Add( new System.Data.SqlClient.SqlParameter( " @Original_Fax " , System.Data.SqlDbType.NVarChar, 24 , System.Data.ParameterDirection.Input, false , ((System.Byte)( 0 )), ((System.Byte)( 0 )), " Fax " , System.Data.DataRowVersion.Original, null )); this .sqlDeleteCommand1.Parameters.Add( new System.Data.SqlClient.SqlParameter( " @Original_Phone " , System.Data.SqlDbType.NVarChar, 24 , System.Data.ParameterDirection.Input, false , ((System.Byte)( 0 )), ((System.Byte)( 0 )), " Phone " , System.Data.DataRowVersion.Original, null )); this .sqlDeleteCommand1.Parameters.Add( new System.Data.SqlClient.SqlParameter( " @Original_PostalCode " , System.Data.SqlDbType.NVarChar, 10 , System.Data.ParameterDirection.Input, false , ((System.Byte)( 0 )), ((System.Byte)( 0 )), " PostalCode " , System.Data.DataRowVersion.Original, null )); this .sqlDeleteCommand1.Parameters.Add( new System.Data.SqlClient.SqlParameter( " @Original_Region " , System.Data.SqlDbType.NVarChar, 15 , System.Data.ParameterDirection.Input, false , ((System.Byte)( 0 )), ((System.Byte)( 0 )), " Region " , System.Data.DataRowVersion.Original, null )); // // sqlConnection2 // this .sqlConnection2.ConnectionString = " workstation id=\"FANCY-FAMILY\";packet size=4096;user id=sa;data source=\"FANCY-FAMI " + " LY\";persist security info=False;initial catalog=Northwind " ; // // sqlInsertCommand1 // this .sqlInsertCommand1.CommandText = @" INSERT INTO Customers(CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax) VALUES (@CustomerID, @CompanyName, @ContactName, @ContactTitle, @Address, @City, @Region, @PostalCode, @Country, @Phone, @Fax); SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax FROM Customers WHERE (CustomerID = @CustomerID) " ; this .sqlInsertCommand1.Connection = this .sqlConnection2; this .sqlInsertCommand1.Parameters.Add( new System.Data.SqlClient.SqlParameter( " @CustomerID " , System.Data.SqlDbType.NVarChar, 5 , " CustomerID " )); this .sqlInsertCommand1.Parameters.Add( new System.Data.SqlClient.SqlParameter( " @CompanyName " , System.Data.SqlDbType.NVarChar, 40 , " CompanyName " )); this .sqlInsertCommand1.Parameters.Add( new System.Data.SqlClient.SqlParameter( " @ContactName " , System.Data.SqlDbType.NVarChar, 30 , " ContactName " )); this .sqlInsertCommand1.Parameters.Add( new System.Data.SqlClient.SqlParameter( " @ContactTitle " , System.Data.SqlDbType.NVarChar, 30 , " ContactTitle " )); this .sqlInsertCommand1.Parameters.Add( new System.Data.SqlClient.SqlParameter( " @Address " , System.Data.SqlDbType.NVarChar, 60 , " Address " )); this .sqlInsertCommand1.Parameters.Add( new System.Data.SqlClient.SqlParameter( " @City " , System.Data.SqlDbType.NVarChar, 15 , " City " )); this .sqlInsertCommand1.Parameters.Add( new System.Data.SqlClient.SqlParameter( " @Region " , System.Data.SqlDbType.NVarChar, 15 , " Region " )); this .sqlInsertCommand1.Parameters.Add( new System.Data.SqlClient.SqlParameter( " @PostalCode " , System.Data.SqlDbType.NVarChar, 10 , " PostalCode " )); this .sqlInsertCommand1.Parameters.Add( new System.Data.SqlClient.SqlParameter( " @Country " , System.Data.SqlDbType.NVarChar, 15 , " Country " )); this .sqlInsertCommand1.Parameters.Add( new System.Data.SqlClient.SqlParameter( " @Phone " , System.Data.SqlDbType.NVarChar, 24 , " Phone " )); this .sqlInsertCommand1.Parameters.Add( new System.Data.SqlClient.SqlParameter( " @Fax " , System.Data.SqlDbType.NVarChar, 24 , " Fax " )); // // sqlSelectCommand1 // this .sqlSelectCommand1.CommandText = " SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region, " + " PostalCode, Country, Phone, Fax FROM Customers " ; this .sqlSelectCommand1.Connection = this .sqlConnection2; // // sqlUpdateCommand1 // this .sqlUpdateCommand1.CommandText = @" UPDATE Customers SET CustomerID = @CustomerID, CompanyName = @CompanyName, ContactName = @ContactName, ContactTitle = @ContactTitle, Address = @Address, City = @City, Region = @Region, PostalCode = @PostalCode, Country = @Country, Phone = @Phone, Fax = @Fax WHERE (CustomerID = @Original_CustomerID) AND (Address = @Original_Address OR @Original_Address IS NULL AND Address IS NULL) AND (City = @Original_City OR @Original_City IS NULL AND City IS NULL) AND (CompanyName = @Original_CompanyName) AND (ContactName = @Original_ContactName OR @Original_ContactName IS NULL AND ContactName IS NULL) AND (ContactTitle = @Original_ContactTitle OR @Original_ContactTitle IS NULL AND ContactTitle IS NULL) AND (Country = @Original_Country OR @Original_Country IS NULL AND Country IS NULL) AND (Fax = @Original_Fax OR @Original_Fax IS NULL AND Fax IS NULL) AND (Phone = @Original_Phone OR @Original_Phone IS NULL AND Phone IS NULL) AND (PostalCode = @Original_PostalCode OR @Original_PostalCode IS NULL AND PostalCode IS NULL) AND (Region = @Original_Region OR @Original_Region IS NULL AND Region IS NULL); SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax FROM Customers WHERE (CustomerID = @CustomerID) " ; this .sqlUpdateCommand1.Connection = this .sqlConnection2; this .sqlUpdateCommand1.Parameters.Add( new System.Data.SqlClient.SqlParameter( " @CustomerID " , System.Data.SqlDbType.NVarChar, 5 , " CustomerID " )); this .sqlUpdateCommand1.Parameters.Add( new System.Data.SqlClient.SqlParameter( " @CompanyName "
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Insert title here</title> <link type="text/css" rel="stylesheet" href="css/jquery-ui-1.9.2.custom.min.css"> <link type="text/css" rel="stylesheet" href="css/ui.jqgrid.css"> <link rel="stylesheet" type="text/css" media="screen" href="css/ui.multiselect.css"> <script type="text/javascript" src="js/jquery-1.11.0.min.js" ></script> <script type="text/javascript" src="js/jquery-ui-1.9.2.custom.min.js"></script> <script type="text/javascript" src="js/jquery.layout-1.2.0.js"></script> <script type="text/javascript" src="js/i18n/grid.locale-cn.js"></script> <script type="text/javascript" src="js/jquery.jqGrid.min.js"></script> <script type="text/javascript" src="js/jquery.tablednd.js"></script> <script type="text/javascript" src="js/jquery.contextmenu.js"></script> <script type="text/javascript" src="js/ui.multiselect.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#list").jqGrid({ url:"happyEvent/jsonlist", datatype: "json", height: "auto", width:"auto", colNames:['id','时间', '用户名', '标题','内容'], colModel:[ {name:'id',index:'id', width:60, sorttype:"int"}, {name:'time',index:'time', width:90, sorttype:"date"}, {name:'name',index:'name', width:100}, {name:'title',index:'title', width:300, align:"left",sorttype:"float"}, {name:'content',index:'content', width:80, align:"left",sorttype:"float"} ], rowNum:2, rowList:[2,4,6], sortname: 'id', pager:"#pager", multiselect: true, caption: "喜事列表" }); $("#list").jqGrid('navGrid','#pager',{edit:false,add:false,del:false}); }); </script> </head> <body> <table id="list"></table> <div id="pager"></div> </body>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值