一下代码可以实现弹出一个datagrid窗口,该窗口支持up,down以及pageup,pagedown,home,end,enter键盘操作,在按下enter键后将选中的值返回初始窗口的textbox1中。
webform1.aspx
<%@ page language="c#" codebehind="webform1.aspx.cs" autoeventwireup="false" inherits="complextest.webform1" %>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en" >
<html>
<head>
<title>webform1</title>
<meta content="microsoft visual studio .net 7.1" name="generator">
<meta content="c#" name="code_language">
<meta content="javascript" name="vs_defaultclientscript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetschema">
<script language="javascript">
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.下一页:ms sql压缩数据库日志方法.click();
}
if ( keycode == 36 ) { // 定义 home 键快捷功能
document.all.firstpage.click();
}
if ( keycode == 35 ) { // 定义 end 键快捷功能
document.all.上一页:[转载]改进《遍历文件夹并建成目录树》.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();
}
</script>
<script language="javascript" event="onkeydown" for="document">
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键退出
</script>
<style>.hidetr { visibility: hidden }
</style>
</head>
<body ms_positioning="gridlayout">
<form id="form1" method="post" runat="server">
<font face="宋体" >
<asp:datagrid id=datagrid1 runat="server" width="520px" datasource="<%# dataset21 %>" datamember="customers" allowpaging="true" autogeneratecolumns="false" bordercolor="#3366cc" borderstyle="none" borderwidth="1px" backcolor="white" cellpadding="4" font-size="x-small" >
<footerstyle wrap="false" forecolor="#003399" cssclass="hidetr" backcolor="#99cccc"></footerstyle>
<selecteditemstyle font-bold="true" wrap="false" forecolor="#ccff99" backcolor="#009999"></selecteditemstyle>
<edititemstyle wrap="false"></edititemstyle>
<alternatingitemstyle wrap="false"></alternatingitemstyle>
<itemstyle wrap="false" forecolor="#003399" backcolor="white"></itemstyle>
<headerstyle font-bold="true" wrap="false" forecolor="#ccccff" backcolor="#003399"></headerstyle>
<columns>
<asp:boundcolumn datafield="customerid" sortexpression="customerid" headertext="用户编号">
<headerstyle wrap="false"></headerstyle>
<itemstyle wrap="false"></itemstyle>
<footerstyle wrap="false"></footerstyle>
</asp:boundcolumn>
<asp:boundcolumn datafield="companyname" sortexpression="companyname" headertext="公司名称">
<headerstyle wrap="false"></headerstyle>
<itemstyle wrap="false"></itemstyle>
<footerstyle wrap="false"></footerstyle>
</asp:boundcolumn>
<asp:boundcolumn datafield="contactname" sortexpression="contactname" headertext="联系人">
<headerstyle wrap="false"></headerstyle>
<itemstyle wrap="false"></itemstyle>
<footerstyle wrap="false"></footerstyle>
</asp:boundcolumn>
<asp:boundcolumn datafield="address" sortexpression="address" headertext="地址">
<headerstyle wrap="false"></headerstyle>
<itemstyle wrap="false"></itemstyle>
<footerstyle wrap="false"></footerstyle>
</asp:boundcolumn>
</columns>
<pagerstyle horizontalalign="left" forecolor="#003399" backcolor="#99cccc" wrap="false" mode="numericpages"></pagerstyle>
</asp:datagrid><asp:label id="lblpagecount"
runat="server" width="224px">label</asp:label><asp:button id="prevpage"
runat="server" text="<" width="24px"></asp:button><asp:button id="下一页:ms sql压缩数据库日志方法"
runat="server" text=">" width="25px"></asp:button>
<asp:button id="firstpage"
runat="server" text="|<" width="24px"></asp:button>
<asp:button id="上一页:[转载]改进《遍历文件夹并建成目录树》"
runat="server" text=">|" width="28px"></asp:button>
<asp:textbox id="txtpageindex"
runat="server" width="40px"></asp:textbox>
<asp:button id="gotopage"
runat="server" text="转到"></asp:button>
<asp:regularexpressionvalidator id="regularexpressionvalidator1"
runat="server" errormessage="需要输入整数" validationexpression="/d" controltovalidate="txtpageindex"></asp:regularexpressionvalidator></font></form>
</body>
</html>
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
{
/// <summary>
/// webform1 的摘要说明。
/// </summary>
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 下一页:ms sql压缩数据库日志方法;
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 上一页:[转载]改进《遍历文件夹并建成目录树》;
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);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
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.下一页:ms sql压缩数据库日志方法.click += new system.eventhandler(this.button2_click);
this.firstpage.click += new system.eventhandler(this.btnfirst_click);
this.上一页:[转载]改进《遍历文件夹并建成目录树》.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 = "<script language=javascript>";
scriptstring += "maxrowcount ="+pagesize+";"; //对客户端代码设置最大的行数
scriptstring += "rowfocus(0,'"+colvalue+"',0)";//设置初始化时将光标定位到第一行
scriptstring += "</script>";
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.pagecount-1)
{
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.pagecount)&&(i>=0))
{
datagrid1.currentpageindex=i;
mydatabind();
}
}
}
}
}
}
index.aspx
<%@ page language="c#" codebehind="index.aspx.cs" autoeventwireup="false" inherits="complextest.index" %>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en" >
<html>
<head>
<title>index</title>
<meta content="microsoft visual studio .net 7.1" name="generator">
<meta content="c#" name="code_language">
<meta content="javascript" name="vs_defaultclientscript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetschema">
<script language="javascript">
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");
}
</script>
<script for="document" event="onkeydown" language="javascript">
if ( event.keycode == 27 )
{
window.opener='anyone';window.close();
}
</script>
<style>.flattext { font-size: x-small; border-top-style: none; border-bottom: black 1px solid; font-family: 宋体; border-right-style: none; border-left-style: none }
.seltext { font-size: x-small; border-top-style: none; border-bottom: black 1px solid; font-family: 宋体; border-right-style: none; border-left-style: none; background-color: #ffcc66 }
</style>
</head>
<body ms_positioning="gridlayout">
<form id="form1" method="post" runat="server">
<font
face="宋体">
<asp:textbox id="textbox1" runat="server"
cssclass="flattext" readonly="true" backcolor="#ffe0c0" height="20px"></asp:textbox><input
type="button" value="..." onclick="search()">
<asp:label id="label1" runat="server">请选择</asp:label></font></form>
</body>
</html>
新闻热点
疑难解答
图片精选