首先是获得数据并绑定好GridView
客户端javascript代码:
1
function GetPersonnelKPIStep()
2![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
3
4
var sId=GetParam("c_id");
5
6
document.getElementByIdx("hId").value=sId;
7
8
var xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
9
xmlhttp.Open("post","FmPersonnelKPIData.aspx?MethodName=GetPersonnelKPIStep&c_id="+sId+"&c_sort=",false);
10
xmlhttp.Send();
11
var sGridContent=xmlhttp.responseText;
12
13
var iStart=sGridContent.indexOf("<table");
14
var iEnd=sGridContent.indexOf("</table>");
15
document.getElementByIdx("divStep").innerHTML= sGridContent.substring(iStart,iEnd+8);
16
}
因为GirdView最后会翻译成Table在浏览器上显示,所以我只要获得返回流中的Table并将其赋给div的innerHTML属性即可
服务端代码:
1
protected void Page_Load(object sender, EventArgs e)
2![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
3
if (!IsPostBack)
4![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
5
if (sMethodName == "GetPersonnelKPIStep")
6![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
7
GetPersonnelKPIStep(sId, Request.QueryString["c_sort"].ToString());
8
}
9
}
1
public void GetPersonnelKPIStep(string sId, string sSort)
2![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
3
CWSHr cwsHr = new CWSHr();
4
_DateNum = cwsHr.GetPersonnelKPIDateNum(sId);
5
_kpiDatetime = cwsHr.GetPersonnelKPIDateTime(sId);
6
if (_kpiDatetime == null || _kpiDatetime.Length != 2)
7
return;
8![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
_StartDate = Convert.ToDateTime(_kpiDatetime[0]);
10![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
DataSet ds= cwsHr.GetPersonnelKPIStep(sId,sSort);
12
GV_Step.DataSource = ds.Tables[0].DefaultView;
13
GV_Step.DataBind();
14
}
在服务端获得并绑定数据到GridView
获得xml格式的数据:
服务端代码:
public void GetPersonnelKPIStepOne(string sId, string sSort)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
CWSHr cwsHr = new CWSHr();
DataSet ds = cwsHr.GetPersonnelKPIStep(sId, sSort);
Response.Write(ds.GetXml());
Response.End();
}
注意,Response.End()一定要加上
客户端代码:
1
var xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
2
xmlhttp.Open("post","FmPersonnelKPIData.aspx?MethodName=GetPersonnelKPIStepOne&c_id="+sId+"&c_sort="+sSort,false);
3
xmlhttp.Send();
4
var sGridContent=xmlhttp.responseText;
5
6
//alert(sGridContent);
7
var xmlDom=new ActiveXObject("MSXML2.DOMDocument");
8
xmlDom.loadXML(xmlhttp.responseText);
9
var nodes=xmlDom.selectSingleNode("//NewDataSet/Table").childNodes;
10
if (nodes != null)
11![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
12
for (var i=0;i<nodes.length;i++)
13![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
14
if (nodes[i].nodeName=="c_sort")
15
document.getElementByIdx("ETBSort").value=nodes[i].text;
16
else if (nodes[i].nodeName=="c_type")
17
document.getElementByIdx("ETBType").value=nodes[i].text;
18
&