[Visual Basic]
<%@ Import Namespace="System.Data" %><html>
<script language="VB" runat="server">
Dim SortExpression As String Function CreateDataSource() As ICollection
Dim dt As New DataTable()
Dim dr As DataRow
Dim Rand_Num As New Random()
dt.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn("CurrencyValue", GetType(Double)))
Dim i As Integer
For i = 0 To 14
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " & i.ToString()
dr(2) = 1.23 * Rand_Num.Next(1, 15)
dt.Rows.Add(dr)
Next i
Dim dv As New DataView(dt)
dv.Sort = SortExpression
Return dv
End Function 'CreateDataSource
Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
If SortExpression = "" Then
SortExpression = "IntegerValue"
End If
ItemsGrid.DataSource = CreateDataSource()
ItemsGrid.DataBind()
End If
End Sub 'Page_Load
Sub Sort_Grid(sender As Object, e As DataGridSortCommandEventArgs)
SortExpression = e.SortExpression.ToString()
ItemsGrid.DataSource = CreateDataSource()
ItemsGrid.DataBind()
End Sub 'Sort_Grid</script><body> <form runat=server> <h3>DataGrid Sorting Example</h3> <asp:DataGrid id="ItemsGrid" runat="server"
BorderColor="black"
BorderWidth="1"
CellPadding="3"
AllowSorting="true"
OnSortCommand="Sort_Grid"
AutoGenerateColumns="true"> <HeaderStyle BackColor="#00aaaa">
</HeaderStyle> </asp:DataGrid> </form></body>
</html>
[C#]
<%@ Import Namespace="System.Data" %><html>
<script language="C#" runat="server">
string SortExpression; ICollection CreateDataSource()
{
DataTable dt = new DataTable();
DataRow dr;
Random Rand_Num = new Random(); dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
dt.Columns.Add(new DataColumn("StringValue", typeof(string)));
dt.Columns.Add(new DataColumn("CurrencyValue", typeof(double))); for (int i = 0; i < 15; i++)
{
dr = dt.NewRow(); dr[0] = i;
dr[1] = "Item " + i.ToString();
dr[2] = 1.23 * Rand_Num.Next(1, 15); dt.Rows.Add(dr);
} DataView dv = new DataView(dt);
dv.Sort=SortExpression;
return dv;
} void Page_Load(Object sender, EventArgs e)
{ if (!IsPostBack)
{ if (SortExpression == "")
SortExpression = "IntegerValue";
ItemsGrid.DataSource = CreateDataSource();
ItemsGrid.DataBind();
} } void Sort_Grid(Object sender, DataGridSortCommandEventArgs e)
{
SortExpression = e.SortExpression.ToString();
ItemsGrid.DataSource = CreateDataSource();
ItemsGrid.DataBind();
}</script><body> <form runat=server> <h3>DataGrid Sorting Example</h3> <asp:DataGrid id="ItemsGrid" runat="server"
BorderColor="black"
BorderWidth="1"
CellPadding="3"
AllowSorting="true"
OnSortCommand="Sort_Grid"
AutoGenerateColumns="true"> <HeaderStyle BackColor="#00aaaa">
</HeaderStyle> </asp:DataGrid> </form></body>
</html>
<%@ Import Namespace="System.Data" %><html>
<script language="VB" runat="server">
Dim SortExpression As String Function CreateDataSource() As ICollection
Dim dt As New DataTable()
Dim dr As DataRow
Dim Rand_Num As New Random()
dt.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn("CurrencyValue", GetType(Double)))
Dim i As Integer
For i = 0 To 14
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " & i.ToString()
dr(2) = 1.23 * Rand_Num.Next(1, 15)
dt.Rows.Add(dr)
Next i
Dim dv As New DataView(dt)
dv.Sort = SortExpression
Return dv
End Function 'CreateDataSource
Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
If SortExpression = "" Then
SortExpression = "IntegerValue"
End If
ItemsGrid.DataSource = CreateDataSource()
ItemsGrid.DataBind()
End If
End Sub 'Page_Load
Sub Sort_Grid(sender As Object, e As DataGridSortCommandEventArgs)
SortExpression = e.SortExpression.ToString()
ItemsGrid.DataSource = CreateDataSource()
ItemsGrid.DataBind()
End Sub 'Sort_Grid</script><body> <form runat=server> <h3>DataGrid Sorting Example</h3> <asp:DataGrid id="ItemsGrid" runat="server"
BorderColor="black"
BorderWidth="1"
CellPadding="3"
AllowSorting="true"
OnSortCommand="Sort_Grid"
AutoGenerateColumns="true"> <HeaderStyle BackColor="#00aaaa">
</HeaderStyle> </asp:DataGrid> </form></body>
</html>
[C#]
<%@ Import Namespace="System.Data" %><html>
<script language="C#" runat="server">
string SortExpression; ICollection CreateDataSource()
{
DataTable dt = new DataTable();
DataRow dr;
Random Rand_Num = new Random(); dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
dt.Columns.Add(new DataColumn("StringValue", typeof(string)));
dt.Columns.Add(new DataColumn("CurrencyValue", typeof(double))); for (int i = 0; i < 15; i++)
{
dr = dt.NewRow(); dr[0] = i;
dr[1] = "Item " + i.ToString();
dr[2] = 1.23 * Rand_Num.Next(1, 15); dt.Rows.Add(dr);
} DataView dv = new DataView(dt);
dv.Sort=SortExpression;
return dv;
} void Page_Load(Object sender, EventArgs e)
{ if (!IsPostBack)
{ if (SortExpression == "")
SortExpression = "IntegerValue";
ItemsGrid.DataSource = CreateDataSource();
ItemsGrid.DataBind();
} } void Sort_Grid(Object sender, DataGridSortCommandEventArgs e)
{
SortExpression = e.SortExpression.ToString();
ItemsGrid.DataSource = CreateDataSource();
ItemsGrid.DataBind();
}</script><body> <form runat=server> <h3>DataGrid Sorting Example</h3> <asp:DataGrid id="ItemsGrid" runat="server"
BorderColor="black"
BorderWidth="1"
CellPadding="3"
AllowSorting="true"
OnSortCommand="Sort_Grid"
AutoGenerateColumns="true"> <HeaderStyle BackColor="#00aaaa">
</HeaderStyle> </asp:DataGrid> </form></body>
</html>
解决方案 »
- 求助了!!关于js读取cookie 中文乱码问题?
- 高分:如何判断某一个链接是否有效,如果,无效的话,就出现特定的链接
- 求救 如何隐藏gridview里的模板列
- 求《ASP.net 服务器控件与组件开发》电子书籍下载地址
- 点IE的后退按钮时,刷新画面的Dropdownlist的值总是会滞后一步,这时为什么?
- 我先装了VS.NET,后装了IIS,没法建立ASP.NET WEB应用程序了,怎么办?
- 为什么一开始添加时,xml文件会的最上面会有一空白行,全部为null,添加的代码如下,请问问题出在哪里?一上午都没解决,请各位多指教了
- 一个想不通的问题,请大家看看
- 求Treeview参数详解
- javascript 验证时间 在线等,能用马上结帖
- 求教!在线等-----
- 如何用asp.net向exchange server 2000中添加用户、邮箱啊?
也可以点击的排序
public void sortrows(object sender, DataGridSortCommandEventArgs objargs)
{
//此处是datagrid排序响应过程
sortorder = objargs.SortExpression.ToString();
binddatagrid();
}
public void binddatagrid()
{
//此处是gatagrid的数据绑定过程
DataGrid1.PageSize = 5;
DataGrid1.PagerStyle.Mode = PagerMode.NumericPages;
string varsql = "select * from telrecord";
myconnclass myclass =new conndbdll.myconnclass();
string mytable="mytable";
DataSet mydataset=myclass.DataAdapter(varsql,mytable);
DataView mydataview = new DataView(mydataset.Tables["mytable"]);
mydataview.Sort = sortorder;
DataGrid1.DataSource = mydataview;
DataGrid1.DataBind();
}
DataGrid1.DataSource=DataSet1.Tables[0].DefaultView;
DataGrid1.DataBound();
page_load时
SqlDataAdapter.Fill(dataSet11)
dg.DataSource=datSet11.Tables[0].defaultView
dg.DataBind();
而mysort(object send,DataGridSortItemCommandEventArgs e)
{
DataView dv=dataSet11.Tables[0].defaultview;
dv.Sort=SortExpression;
dg.DataSource=dv;
dg.DataBind();}
运行时都变成空的了,怎么办啊!