可以參考以下代碼﹕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 ;
}
{
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 ;
}
解决方案 »
- 一个事务,但要操作两个数据库,有办法实现吗?
- C#安装程序如何自动安装.Net Framwork
- 我机子是在公司的局域网内,公司是通过路由器上网的
- 再20分奉送,刚才的问题还没问完:大家都使用哪种组合呀?dataset+datagrid还是....
- 模版问题!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 急求jmail实现 接收和发送 html格式邮件代码 ( vb.net)
- 如何获取动态加载的用户控件的值
- 问个关于TabStrip的问题.
- 关于大访量网上saas系统(即租用式),请问在选数据库,设计语言,平台框架,开发过程就注意什么.
- 如何在ASP.NET里用VB.NET动态增加一个服务器端的控件?
- asp.net生成Excel为什么一保存就死机?(内附代码)
- 这是怎么回事?
<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为显示数据库的函数,大家看看怎样才能做到排序,帮帮菜鸟
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