DataGrid绑定两个DataTable

本文介绍了一种将内网和外网数据整合到同一DataGrid的方法,并通过WebService获取外网数据,最后对整合后的数据进行了排序处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

项目要统计从内网、外网的信息数据,通过WebService查询出外网的数据后,与内网的数据一起绑定到一个DataGrid,
在网上搜索了一下,答案马上就出来了

ContractedBlock.gifExpandedBlockStart.gif
 1None.gif            BusinessFacade.TestQuestion TQ = new TestQuestion ();
 2None.gif             DataTable table = new DataTable ();
 3None.gif           table.Columns .Add ("Position",typeof(string));
 4None.gif           DwService.Service service = new Service ();
 5None.gif            DataSet inner= TQ.TestUserGetAll (testpageid,Functions.ToDateTime(starttime),Functions.ToDateTime (endtime) );
 6None.gif                    if(inner!=null && inner.Tables [0].Rows .Count >0)
 7ExpandedBlockStart.gifContractedBlock.gif                    dot.gif{
 8InBlock.gif                        DataTable innertable = inner.Tables [0];
 9InBlock.gif                        innertable.Columns .Add ("Position",typeof(string));
10InBlock.gif                        for(int m=0;m<innertable.Rows .Count ;m++)
11ExpandedSubBlockStart.gifContractedSubBlock.gif                        dot.gif{
12InBlock.gif                            DataRow row = innertable.Rows [m];
13InBlock.gif                            row["Position"= "内网";
14ExpandedSubBlockEnd.gif                        }

15InBlock.gif                        table = innertable;
16ExpandedBlockEnd.gif                    }

17None.gif                    DataSet outer = service.TestUserGetAll (testpageid,Functions.ToDateTime(starttime),Functions.ToDateTime (endtime) );
18None.gif                    if(outer!=null && outer.Tables [0].Rows.Count >0)
19ExpandedBlockStart.gifContractedBlock.gif                    dot.gif{
20InBlock.gif                        DataTable outtable = outer.Tables [0];
21InBlock.gif                        outtable.Columns .Add ("Position",typeof(string));
22InBlock.gif                        DataRow dr;
23InBlock.gif                        for(int i=0;i<outtable.Rows .Count ;i++)
24ExpandedSubBlockStart.gifContractedSubBlock.gif                        dot.gif{
25InBlock.gif                            outtable.Rows [i]["Position"= "外网";
26InBlock.gif                            dr = table.NewRow ();
27InBlock.gif                            for(int j=0;j<table.Columns.Count ;j++)
28ExpandedSubBlockStart.gifContractedSubBlock.gif                            dot.gif{
29InBlock.gif                                dr[j] = outtable.Rows [i][j];
30ExpandedSubBlockEnd.gif                            }

31InBlock.gif                            table.Rows .Add (dr );
32ExpandedSubBlockEnd.gif                        }

33ExpandedBlockEnd.gif                    }

34None.gif      if(table!=null && table.Rows .Count >0)
35ExpandedBlockStart.gifContractedBlock.gif                dot.gif{
36InBlock.gif                    DataView daview = table.DefaultView ;
37InBlock.gif                    daview.Sort = "starttime desc";
38InBlock.gif                    ViewState["table"= table;
39InBlock.gif                    
40InBlock.gif                    dgTestUser.DataSource = table;
41InBlock.gif                    dgTestUser.DataBind ();
45InBlock.gif                    
46ExpandedBlockEnd.gif                }

 把两个DataTable组合成一个后,用DataView对DataGrid进行排序。

转载于:https://www.cnblogs.com/nonsuch/archive/2007/06/11/779217.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值