古老的AJAX做法...
DataGrid只能看,不能用...
JavaScript Code
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
var
client=
null
; if (window.XMLHttpRequest){ client = new XMLHttpRequest(); } else if (window.ActiveXObject){ client = new ActiveXObject( "Microsoft.XMLHTTP" ); } function getDataGrid(app_date) { try { var url= "Grid.aspx" ; url=url+ '?app_data=' +document.getElementById( 'app_data' ).value; client.open( "GET" , url); client.onreadystatechange = callBack; client.send(); } catch (ex) { alert(ex.message); } } function callBack(response) { try { if (client.readyState == 4 && client.status == 200 ) { document.getElementById( "GridSection" ).innerHTML=client.responseText; } } catch (ex) { alert(ex.message); } } |
C# Code
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
protected
void
Page_Load(
object
sender, System.EventArgs e) { if (! this .IsPostBack) { if (Request[ "app_data" ] != null ) { this .SetBind(( string )Request[ "app_data" ]); } } } //取得主DataGrid畫面資料 private void SetBind( string app_data) { //資料 DataTable Store = Operator.getDataGridDataSource(app_date).Tables[ 0 ]; DataView StoreView = new DataView(Store); GridCS.DataSource = StoreView; GridCS.DataBind(); //將Grid寫到網頁 System.IO.StringWriter sw = new System.IO.StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); Response.ClearHeaders(); Response.Clear(); Response.Charset = "UTF-8" ; GridCS.RenderControl(hw); Response.Write(sw.ToString()); Response.End(); } |