All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
ASP.NET存取SQLServer数据库图片_[Asp.Net教程]
在ASP.NET中web.config配置数据库_[Asp.Net教程]
php中rename()函数的妙用_php资料_编程技术
初学,ASP.NET,AJAX,(一):构建,ASP.NET,AJAX,开发环境_[Asp.Net教程]
datagrid导出excel文件给客户端下载的3种方法_[Asp.Net教程]
菜鸟的最爱,.NET经典代码汇总(四)_.net资料_编程技术
小结:PHP动态网页程序两个有用的小技巧_php资料_编程技术
资深网管教你一步步安装MYSQL数据库_php资料_编程技术
当ASP.NET撞上JSF之应用程序的国际化_[Asp.Net教程]
C#教程:C#数据类型之值的类型
Reading number is top 10 pictures
The money of more than 100 countries and regions6
采访谢楠
Sora aoi in China1
Fierce! China's special forces training the devil2
Sell the barbecue as says father du breul5
XuYing poker perspective garment debut
中国文革时期的色情图片1
谁认识这位校花
Absolutely shocked. National geographic 50 animal photographys7
The real super beauty5
Download software ranking
Boxer's Top ten classic battle2
Twenty piece of palm leaf
Popkart Cracked versions Mobile phone games
变速齿轮3.26
Macromedia Dreamweaver 8
尖东毒玫瑰A
Boxer vs Yellow4
Unix video tutorial6
Unix video tutorial7
Visual C++界面编程技术
delv published in(发表于) 2014/1/8 7:03:18 Edit(编辑)
一个Ajax.NET的查询实例_[Asp.Net教程]

一个Ajax.NET的查询实例_[Asp.Net教程]

一个Ajax.NET的查询实例_[Asp.Net教程]























因為項目中只能用.net 1.1,所以atlas是用不了了,只能玩玩AjaxProfession.net, 下面是一個查詢的案例。 在頁面上放置一個DataGrid1,各種查詢結果均放入其中,在client端的JS中將SQL語句傳給server端的方法,執行一個查詢,並可以控制雙擊行是否展開一個新的查詢。可將DataGrid1的內容導出到excel中、模擬gmail的Ajax的loading運用




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;
using System.Data.SqlClient;
using System.IO;
namespace eol
{
/**////


/// index 的摘要描述。
///

public class index : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected WebControlLibrary.InputCalendar startTime;
protected WebControlLibrary.InputCalendar endTime;
protected WebControlLibrary.InputCalendar pStartTime;
protected WebControlLibrary.InputCalendar pEndTime;
protected System.Data.SqlClient.SqlConnection Conn=new SqlConnection();
protected System.Web.UI.WebControls.TextBox eformsn;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.DataGrid DataGrid1=new DataGrid();
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.HtmlControls.HtmlInputText applicant;
public string toExcel;

private void Page_Load(object sender, System.EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(eol.index));
}




public DataSet DB(string dataName, string sqlCmd)
{
string connStr="server=172.16.0.120;uid=msikdb;pwd=dbmsik;database="+dataName;
Conn.ConnectionString=connStr;
try
{
Conn.Open();
}
catch(Exception ex)
{
Conn.Close();
Response.Write(ex.Message);
}
SqlCommand cmd=new SqlCommand(sqlCmd, Conn);
SqlDataAdapter da=new SqlDataAdapter();
da.SelectCommand=cmd;
DataSet ds = new DataSet();
da.Fill(ds);
Conn.Close();
return ds;
}




Web Form 設計工具產生的程式碼#region Web Form 設計工具產生的程式碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 此為 ASP.NET Web Form 設計工具所需的呼叫。
//
InitializeComponent();
base.OnInit(e);
}

/**////


/// 此為設計工具支援所必須的方法 - 請勿使用程式碼編輯器修改
/// 這個方法的內容。
///

private void InitializeComponent()
{
this.Conn = new System.Data.SqlClient.SqlConnection();
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.DataGrid1.ItemCreated += new System.Web.UI.WebControls.DataGridItemEventHandler(this.getPageIndexStyle);
this.Load += new System.EventHandler(this.Page_Load);




}
#endregion





private void getPageIndexStyle(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{

if(e.Item.ItemType == ListItemType.Pager)
{
e.Item.Cells[0].Text="Total Row:"+this.DataGrid1.Items.Count.ToString();
}
}

[AjaxPro.AjaxMethod]
public string AjaxData(string sSql, bool clientEvent)
{
if (clientEvent)
{
DataGrid1.ItemDataBound+=new DataGridItemEventHandler(DataGrid1_ItemDataBound);
}
// DataGrid1.AllowPaging=true;
// DataGrid1.PagerStyle.Position=PagerPosition.Top;
// DataGrid1.PagerStyle.Mode=PagerMode.NumericPages;
// DataGrid1.ItemCreated+=new DataGridItemEventHandler(getPageIndexStyle);
DataGrid1.DataSource=DB("query",sSql);
DataGrid1.HeaderStyle.BackColor=System.Drawing.Color.Blue;
DataGrid1.Width=Unit.Percentage(100);
DataGrid1.HeaderStyle.ForeColor=System.Drawing.Color.White;
DataGrid1.DataBind();


System.Text.StringBuilder sb=new System.Text.StringBuilder();
System.IO.StringWriter sw=new System.IO.StringWriter(sb);
System.Web.UI.HtmlTextWriter htw=new HtmlTextWriter(sw);
this.DataGrid1.RenderControl(htw);
string s=sb.ToString().Replace(" 上午 12:00:00", "");
this.toExcel=s;
Session["txtExcel"]=s;
return s;
}

public void setToExcel()
{
//下面這行很重要,attachment 參數表示作為附件下載,您可以改成online在線打開
//filename=FileFlow.xls 指定輸出文件的名稱,注意其擴展名和指定文件類型相符,可以為:.doc    .xls    .txt  .htm  
Response.AppendHeader("Content-Disposition","attachment;filename=EOL_"+eformsn.Text+".xls");
Response.ContentEncoding=System.Text.Encoding.GetEncoding("big5"); 
//Response.ContentType指定文件類型 可以為application/ms-excel,application/ms-word ,application/ms-txt,application/ms-html或其他瀏覽器可直接支持文檔 
Response.ContentType = "application/ms-excel";




Response.Write(this.toExcel);
Response.Write(Session["txtExcel"]);
Session.Abandon();
Response.End();
}




private void Button2_Click(object sender, System.EventArgs e)
{
setToExcel();
}




private void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
ListItemType itemtype=(ListItemType)e.Item.ItemType;
if (itemtype!=ListItemType.Header && itemtype!=ListItemType.Footer && itemtype!=ListItemType.Separator)
{
e.Item.Attributes.Add("ondblclick", "showDetail("+e.Item.Cells[1].Text+");");
e.Item.Attributes.Add("onmouseover","this.className='mouseOn'");
e.Item.Attributes.Add("onmouseout", "this.className=''");
}
}




}
}
Client端的js:




来源:网络












































添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.