一下代码可以实现弹出一个DataGrid窗口,该窗口支持up,down以及pageup,pagedown,home,end,Enter键盘操作,在按下Enter键后将选中的值返回初始窗口的TextBox1中。

webform1.aspx
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="ComplexTest.WebForm1" %>
var oldrow
var currowno;
var strReturn; //存储返回值
var newColor='#C0C0C0';
var oldColor;
var MaxRowCount;
function SelectOK(text)
{
eval("parent.opener.document.all.TextBox1.value = text");//向弹出该窗体的窗口返回值
parent.close();
}
function ChangePage(KeyCode)
{
if ( KeyCode == 33 ) { // 定义 PageUp 键快捷功能
document.all.PrevPage.click();//调用服务器控件的相应功能
}
if ( KeyCode == 34 ) { // 定义 PageDown 键快捷功能
document.all.NextPage.click();
}
if ( KeyCode == 36 ) { // 定义 Home 键快捷功能
document.all.FirstPage.click();
}
if ( KeyCode == 35 ) { // 定义 End 键快捷功能
document.all.LastPage.click();
}
if ( KeyCode == 38 ) { // ↑ 键快捷功能
MoveUp();
}
if ( KeyCode == 40 ) { // ↓ 键快捷功能
MoveDown();
}
if ( KeyCode == 37 ) { // ← 键快捷功能( 上一层 )
//QueryParent();
}
if ( KeyCode == 39 ) { // → 键快捷功能( 下一层 )
//QueryChild();
}
if ( KeyCode == 13 ) { // 回车键
SelectOK(strReturn);
}
}
function RowFocus(rowno,strValue,bFirst)
{
if (bFirst!=0){//如果不是第一次调用该函数
oldrow.style.backgroundColor=oldColor;//将旧的一行设置回原来的颜色
}
strReturn = strValue;//strReturn中保存要返回的值
oldrow=document.all('ROW' + rowno);//在oldrow中保存旧的行
oldColor=document.all('ROW' + rowno).style.backgroundColor;//在oldColor中保存当前行的颜色
document.all('ROW' + rowno).style.backgroundColor= newColor;//设置当前行的颜色为提醒色
currowno=rowno;//在currowno中保存当前行号
}
function MoveUp() {
if(currowno==0)//如果已经是最上一行则设置光标到最底一行
currowno=MaxRowCount-1;
else
currowno=currowno-1;//否则上移一行
document.all('ROW' + currowno).click();//调用该行的点击函数
}
function MoveDown() {
if(currowno==MaxRowCount-1)//如果已经是最底一行则设置光标到最底一行上一行
currowno=0;
else
currowno=currowno+1;//否则下移一行
document.all('ROW' + currowno).click();
}
if ( event.keyCode == 34 || event.keyCode == 33 || event.keyCode == 35 || event.keyCode == 36 || event.keyCode == 37 || event.keyCode == 38 || event.keyCode == 39 || event.keyCode == 40 || event.keyCode == 13 )
{
ChangePage(event.keyCode);//改变页面显示
}
if ( event.keyCode == 27 ) parent.close();//按下ESC键退出
Webform1.aspx.cs
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 ComplexTest
{
///
/// WebForm1 的摘要说明。
///
public class WebForm1 : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected System.Web.UI.WebControls.Button PrevPage;
protected System.Web.UI.WebControls.Button NextPage;
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.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected ComplexTest.DataSet2 dataSet21;
protected System.Web.UI.WebControls.Button FirstPage;
protected System.Web.UI.WebControls.Button LastPage;
protected System.Web.UI.WebControls.Label lblPageCount;
protected System.Web.UI.WebControls.Button GotoPage;
protected System.Web.UI.WebControls.TextBox txtPageIndex;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
MyDataBind();
}
}
#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.sqlSelectCommand2 = new System.Data.SqlClient.SqlCommand();
this.sqlInsertCommand2 = new System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand2 = new System.Data.SqlClient.SqlCommand();
this.sqlDeleteCommand2 = new System.Data.SqlClient.SqlCommand();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.dataSet21 = new ComplexTest.DataSet2();
((System.ComponentModel.ISupportInitialize)(this.dataSet21)).BeginInit();
this.DataGrid1.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemDataBound);
this.PrevPage.Click += new System.EventHandler(this.Button1_Click);
this.NextPage.Click += new System.EventHandler(this.Button2_Click);
this.FirstPage.Click += new System.EventHandler(this.btnFirst_Click);
this.LastPage.Click += new System.EventHandler(this.btnLast_Click);
this.GotoPage.Click += new System.EventHandler(this.GotoPage_Click);
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=SOHO;packet size=4096;user id=sa;data source=SOHO;persist security" +
" info=False;initial catalog=Northwind";
//
// sqlSelectCommand2
//
this.sqlSelectCommand2.CommandText = "SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region," +
" PostalCode, Country, Phone, Fax FROM Customers";
this.sqlSelectCommand2.Connection = this.sqlConnection1;
//
// sqlInsertCommand2
//
this.sqlInsertCommand2.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.sqlInsertCommand2.Connection = this.sqlConnection1;
this.sqlInsertCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CustomerID", System.Data.SqlDbType.NVarChar, 5, "CustomerID"));
this.sqlInsertCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CompanyName", System.Data.SqlDbType.NVarChar, 40, "CompanyName"));
this.sqlInsertCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ContactName", System.Data.SqlDbType.NVarChar, 30, "ContactName"));
this.sqlInsertCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ContactTitle", System.Data.SqlDbType.NVarChar, 30, "ContactTitle"));
this.sqlInsertCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Address", System.Data.SqlDbType.NVarChar, 60, "Address"));
this.sqlInsertCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@City", System.Data.SqlDbType.NVarChar, 15, "City"));
this.sqlInsertCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Region", System.Data.SqlDbType.NVarChar, 15, "Region"));
this.sqlInsertCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PostalCode", System.Data.SqlDbType.NVarChar, 10, "PostalCode"));
this.sqlInsertCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Country", System.Data.SqlDbType.NVarChar, 15, "Country"));
this.sqlInsertCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Phone", System.Data.SqlDbType.NVarChar, 24, "Phone"));
this.sqlInsertCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Fax", System.Data.SqlDbType.NVarChar, 24, "Fax"));
//
// sqlUpdateCommand2
//
this.sqlUpdateCommand2.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.sqlUpdateCommand2.Connection = this.sqlConnection1;
this.sqlUpdateCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CustomerID", System.Data.SqlDbType.NVarChar, 5, "CustomerID"));
this.sqlUpdateCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CompanyName", System.Data.SqlDbType.NVarChar, 40, "CompanyName"));
this.sqlUpdateCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ContactName", System.Data.SqlDbType.NVarChar, 30, "ContactName"));
this.sqlUpdateCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ContactTitle", System.Data.SqlDbType.NVarChar, 30, "ContactTitle"));
this.sqlUpdateCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Address", System.Data.SqlDbType.NVarChar, 60, "Address"));
this.sqlUpdateCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@City", System.Data.SqlDbType.NVarChar, 15, "City"));
this.sqlUpdateCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Region", System.Data.SqlDbType.NVarChar, 15, "Region"));
this.sqlUpdateCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PostalCode", System.Data.SqlDbType.NVarChar, 10, "PostalCode"));
this.sqlUpdateCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Country", System.Data.SqlDbType.NVarChar, 15, "Country"));
this.sqlUpdateCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Phone", System.Data.SqlDbType.NVarChar, 24, "Phone"));
this.sqlUpdateCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Fax", System.Data.SqlDbType.NVarChar, 24, "Fax"));
this.sqlUpdateCommand2.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.sqlUpdateCommand2.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.sqlUpdateCommand2.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.sqlUpdateCommand2.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.sqlUpdateCommand2.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.sqlUpdateCommand2.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.sqlUpdateCommand2.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.sqlUpdateCommand2.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.sqlUpdateCommand2.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.sqlUpdateCommand2.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.sqlUpdateCommand2.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));
//
// sqlDeleteCommand2
//
this.sqlDeleteCommand2.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.sqlDeleteCommand2.Connection = this.sqlConnection1;
this.sqlDeleteCommand2.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.sqlDeleteCommand2.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.sqlDeleteCommand2.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.sqlDeleteCommand2.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.sqlDeleteCommand2.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.sqlDeleteCommand2.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.sqlDeleteCommand2.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.sqlDeleteCommand2.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.sqlDeleteCommand2.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.sqlDeleteCommand2.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.sqlDeleteCommand2.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));
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand2;
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand2;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand2;
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.sqlUpdateCommand2;
//
// dataSet21
//
this.dataSet21.DataSetName = "DataSet2";
this.dataSet21.Locale = new System.Globalization.CultureInfo("zh-CN");
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.dataSet21)).EndInit();
}
#endregion
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if((e.Item.ItemType==ListItemType.Item)||(e.Item.ItemType==ListItemType.AlternatingItem))
{
string strField=e.Item.Cells[0].Text;//指定要返回的字段,目前是返回第0行,可以改成其他的字段
e.Item.Attributes.Add("onDblClick","SelectOK('"+strField+"')");//双击时也可以返回选中结果
e.Item.Attributes.Add("onClick","RowFocus("+e.Item.ItemIndex+",'"+strField+"',1)");//单击时执行选中行
e.Item.Attributes.Add("id","ROW"+e.Item.ItemIndex);//给表格中的每一行起个名字以方便客户端代码调用
if(e.Item.ItemIndex==0) //设置初始化时的Javascript语句
{
CreateJavascript(strField,DataGrid1.PageSize);//初始化客户端代码
}
//e.Item.Attributes.Add("onMouseOver","RowFocus("+e.Item.ItemIndex+",'"+e.Item.Cells[0].Text +"',1)");
}
}
private void CreateJavascript(string ColValue,int PageSize)
{
//画面初始化Javascript语句,将凸现行设置为首行,并设置页面行数
String scriptString = "";
if(!this.IsStartupScriptRegistered("Startup"))
this.RegisterStartupScript("Startup", scriptString);
}
private void Button1_Click(object sender, System.EventArgs e)
{
if(DataGrid1.PageCount>0)
{
if(DataGrid1.CurrentPageIndex>0)
{
DataGrid1.CurrentPageIndex = DataGrid1.CurrentPageIndex-1;
MyDataBind();
}
}
}
private void Button2_Click(object sender, System.EventArgs e)
{
if(DataGrid1.PageCount>0)
{
if(DataGrid1.CurrentPageIndex { DataGrid1.CurrentPageIndex =DataGrid1.CurrentPageIndex+1; MyDataBind(); } } } private void btnFirst_Click(object sender, System.EventArgs e) { if(DataGrid1.PageCount>0) { DataGrid1.CurrentPageIndex = 0; MyDataBind(); } } private void btnLast_Click(object sender, System.EventArgs e) { if(DataGrid1.PageCount>0) { DataGrid1.CurrentPageIndex =DataGrid1.PageCount-1; MyDataBind(); } } private void MyDataBind() { sqlDataAdapter1.Fill(dataSet21); DataGrid1.DataBind(); if(DataGrid1.PageCount>0) { int PageIndex = DataGrid1.CurrentPageIndex+1; lblPageCount.Text = "共"+DataGrid1.PageCount+"页,当前为第"+PageIndex.ToString()+"页"; txtPageIndex.Text = PageIndex.ToString(); } } private void GotoPage_Click(object sender, System.EventArgs e) { if(DataGrid1.PageCount>0) { if(txtPageIndex.Text.Length>0) { int i=Convert.ToInt16(txtPageIndex.Text)-1; if((i { DataGrid1.CurrentPageIndex=i; MyDataBind(); } } } } } } index.aspx <%@ Page language="c#" Codebehind="index.aspx.cs" AutoEventWireup="false" Inherits="ComplexTest.index" %>
function Search() //选择发货单位
{
var strURL;
strURL="WebForm1.aspx";
window.open(strURL,"SELECT_ONE_BASE","TOOLBAR=NO,MENUBAR=NO,RESIZABLE=YES,TOP=0,LEFT=0,WIDTH=720PT,HEIGHT=460PT");
}
if ( event.keyCode == 27 )
{
window.opener='anyone';window.close();
}

