以XMLHttpRequest方式填入DataGrid

来源:互联网 发布:java io继承图 编辑:程序博客网 时间:2024/06/03 00:15

 古老的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();
        }

<script type="text/javascript"><!--google_ad_client = "ca-pub-1944176156128447";/* cnblogs 首页横幅 */google_ad_slot = "5419468456";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击