可以參考以下代碼﹕private void DBind()
{
this.dGridSource.DataSource = CreateDataSource();
this.dGridSource.DataKeyField = strKeys;
this.dGridSource.DataBind();
}
protected ICollection CreateDataSource() 
{
DataView dv = new DataView(dt);
if (SortExpression !="" ) dv.Sort = SortExpression;
return dv ;
}

解决方案 »

  1.   

    pengweihua(pwh) 我只能看懂vb语言啊
      

  2.   

    datagrid控件:
    <asp:datagrid
    id=dg
    runat=server
    gridlines=both
    cellspacing=2
    autogeneratecolumns=false
    onsortcmmand=gridsort
    allowsorting=true
    allowpaging=true
    pagesize=3
    onpageindexchanged="changepage"
    pagerstyle-nextpagetext="下一页》"
    pagerstyle-prevpagetext="《上一页"
    oneditcommand="gridedit"
    oncancelcommand="gridcancel"
    onupdatecommand="gridupdate"
    ondeletecommand="griddelete"
    datakeyfield="studentid">
    <columns>
    <asp:boundcolumn datafield="studentid" headertext="学生号" readonly=true/>
    <asp:boundcolumn datafield="name" headertext="姓名" readonly=true/>
    <asp:boundcolumn datafield="age" headertext="年龄" readonly=true/>
    <asp:boundcolumn datafield="address" headertext="地址"/>
    <asp:editcommandcolumn headertext="操作" edittext="编辑" updatetext="修改" canceltext="取消"/>
    <asp:buttoncolumn buttontype=pushbutton text="删   除" commandname="delete"/>
    </columns>
    </asp:datagrid>排序函数:
    sub gridsort(source as object,e as datagridsortcommandeventargs)
    session("sortexpression")=e.sortexpression
    bindgrid
    end sub其中 bindgrid为显示数据库的函数,大家看看怎样才能做到排序,帮帮菜鸟
      

  3.   

    Create an event handler for the grid's SortCommand event. In the method: 
    Get the sort key (the value you set in the Sort expression) from the SortExpression property of the DataGridSortCommandEventArgs argument. 
    Sort the data. 
    Rebind the data from the data source. 
    The following example shows how to sort by handling the SortCommand event. The method gets the sort key value and uses it to set the Sort property of a DataView object. The code then rebinds the grid to the DataView object, which automatically returns the data in sorted order. ' Visual Basic
    Private Sub DataGrid1_SortCommand(ByVal source As Object, _
    ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) _
    Handles DataGrid1.SortCommand
       DataView1.Sort = e.SortExpression
       DataGrid1.DataBind()
    End Sub
      

  4.   

    建议使用 VS.net 这一切 ,轻松 搞掂