日期:2014-05-19  浏览次数:20394 次

关于onsorting的问题:我点标题后页面只是刷新一下,并没有排序啊,怎么回事啊?20分
aspx里:

<form   id= "form1 "   runat= "server ">
<asp:GridView   AllowSorting= "True "   AllowPaging= "true "   pagesize= "12 "   AutoGenerateColumns= "False "   OnPageIndexChanging= "gvchange "   id= "gv "   OnSorting= "gvsort "   runat= "server ">
<Columns>
<asp:BoundField   DataField= "biaoti "   HeaderText= "标题 "   ReadOnly= "True "   SortExpression= "biaoti "/>
<asp:BoundField   DataField= "shijian "   HeaderText= "时间 "   SortExpression= "shijian "/>
</Columns>
</asp:GridView>
</form>


cs里:

                protected   void   gvsort(object   sender,   GridViewSortEventArgs   e)
        {
                ViewState[ "sortexpression "]   =   e.SortExpression;
                if   (ViewState[ "sortdirection "]   ==   null)
                {
                        ViewState[ "sortdirection "]   =   "asc ";
                }
                else
                {
                        if   (ViewState[ "sortdirection "].ToString()   ==   "asc ")
                        {
                                ViewState[ "sortdirection "]   =   "desc ";
                        }
                        else
                        {
                                ViewState[ "sortdirection "]   =   "asc ";
                        }
                }
                bindgv();
        }


无论我点标题字段还是时间字段都不排序,只是刷新了下页面,请问怎么回事啊?

------解决方案--------------------
前台页面加:AllowSorting= "True " OnSortCommand= "dg_CorpInfo_SortCommand "
后台:
protected void dg_CorpInfo_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
if (ViewState[ "SortExpression "] != null)
{
if (ViewState[ "SortExpression "].ToString() == e.SortExpression.ToString())
{
string cSortExpression = " ";
if (ViewState[ "SortExpression "].ToString().Length > 5)
{