日期:2014-05-17  浏览次数:20532 次

dwz 表头排序
dwz 如何使用 表头排序,给个详细例子 带截图的 我用的是asp.net

------解决方案--------------------

asp.net 点击表头排序及分页代码 


 
aspx:
 
<script type="text/javascript" src="jquery-1.2.6.js"></script>
<script language="javascript" type="text/javascript">
var getPageData=function(i,pageCount)
{
$.ajax({
url:'....aspx?'+new Date()+'&page='+i+'&url='+document.getElementById('ctl00_ContentArea_hidUrl').value+'&pageCount='+pageCount+'&Type='+document.getElementById('ctl00_ContentArea_hidType').value,
type:'get',
success:function(data,textStatus)
{
// $('#ShowData').text(data);
// $('#ShowData')[0].innerHTML="";
//$('#ShowData').innerHTML=data;
document.getElementById('ShowData').innerHTML=data;
},
error:function(XMLHttpRequest,textStatus)
{
//debugger;
$('#ShowData').text(XMLHttpRequest.responseText);
},
complete:function(XMLHttpRequest,textStatus)
{

}
});
}
var sortDataGridView=function(sortExpression,sortDirection)
{
//event.returnVaule=false;
$.ajax({
url:'.....aspx?'+new Date()+'&sortEx='+sortExpression+'&url='+document.getElementById('ctl00_ContentArea_hidUrl').value+'&Type='+document.getElementById('ctl00_ContentArea_hidType').value,
type:'get',
success:function(data,textStatus)
{
document.getElementById('ShowData').innerHTML=data;
//$('#ShowData').innerHTML = data;
},
error:function(XMLHttpRequest,textStatus)
{
$('#ShowData').text(XMLHttpRequest.responseText);
},
complete:function(XMLHttpRequest,textStatus)
{

}

});
}
</script>
 
 
 
aspx.cs:
 
Page_Load:
 
 //jquary sort
if (hasKeyName("page"))
{
if (!string.IsNullOrEmpty(Request.QueryString["page"].ToString()))
{
this.GridView1.PageIndex = int.Parse(Request.QueryString["page"].ToString());
ResponseData();
}
}
else
{
if (hasKeyName("sortEx"))
{
sortEx = Request.QueryString["sortEx"].ToString();
try
{
this.GridView1.Sort(sortEx, SortDirection.Ascending);
}
catch (Exception ex)
{
string info = ex.Message;
}
}
}
 
 
 
other:
 
 private bool hasKeyName(string key)
{
string[] keys = Request.QueryString.AllKeys;
foreach (string str in keys)
{
if (String.Compare(key, str, true) == 0)
return true;
}
return false;
}
 
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
string firstHeader = string.Empty;

for (int i = 0; i < e.Row.Cells.Count; i++)
{

LinkButton lt = (LinkButton)e.Row.