谁说模板列不能排序??
在属性生成器里 模板列 同样可以输入排序表达式,同样可以触发SortCommand事件,
你爱怎么排序都行
在属性生成器里 模板列 同样可以输入排序表达式,同样可以触发SortCommand事件,
你爱怎么排序都行
解决方案 »
- FAXCOMLib 发送传真怎么判断发送状态
- 我的网站被挂木马了。请老师帮忙看一下
- 请教下ASP.NET中哪个循环语句更好
- 求高手帮忙
- dropdownList的问题
- 如何在WEB.CONFIG中配置取消对某一页的登录验证
- 各位老大,在线等啊,在win2003下的做好的,拷到服务器上win2000就不行啊,按纽点击没动静,是怎么回事啊
- 关于使用vss管理项目代码的问题
- 求助一个老问题:页面分割的问题,
- 我只用了一个ASPX文件做了一个类似BBS的应用,速度你看快不快
- 关于causevalidation=false,如果同一页面有两个表单怎么办?
- 为什么我在aspx的后台编码中使用treeview控件申明不了节点?
<%@ Import Namespace="System.Data" %>
<html>
<script runat="server">
ICollection CreateDataSource()
{
// Create a Random object to mix up the order of items in the
// sample data.
Random Rand_Num = new Random(); // Create sample data for the DataGrid control.
DataTable dt = new DataTable();
DataRow dr;
// Define the columns of the table.
dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
dt.Columns.Add(new DataColumn("StringValue", typeof(String)));
dt.Columns.Add(new DataColumn("CurrencyValue", typeof(Double)));
// Populate the table with sample values.
for (int i=0; i<=8; i++)
{ dr = dt.NewRow();
dr[0] = i;
dr[1] = "Item " + Rand_Num.Next(1, 15).ToString();
dr[2] = 1.23 * Rand_Num.Next(1, 15);
dt.Rows.Add(dr);
} // To persist the data source between posts to the server,
// store it in session state.
Session["Source"] = dt;
DataView dv = new DataView(dt); return dv;
}
void Page_Load(Object sender, EventArgs e)
{
// Load sample data only once, when the page is first loaded.
if (!IsPostBack)
{
ItemsGrid.DataSource = CreateDataSource();
ItemsGrid.DataBind();
} } void Sort_Grid(Object sender, DataGridSortCommandEventArgs e)
{ // Retrieve the data source from session state.
DataTable dt = (DataTable)Session["Source"]; // Create a DataView from the DataTable.
DataView dv = new DataView(dt); // The DataView provides an easy way to sort. Simply set the
// Sort property with the name of the field to sort by.
dv.Sort = e.SortExpression; // Re-bind the data source and specify that it should be sorted
// by the field specified in the SortExpression property.
ItemsGrid.DataSource = dv;
ItemsGrid.DataBind(); } </script>
<body>
<form runat=server>
<h3>DataGrid SortExpression Example</h3>
<b>Product List</b>
<asp:DataGrid id="ItemsGrid"
BorderColor="black"
BorderWidth="1"
CellPadding="3"
OnSortCommand="Sort_Grid"
AutoGenerateColumns="False"
AllowSorting="True"
runat="server"> <HeaderStyle BackColor="#00aaaa">
</HeaderStyle> <Columns> <asp:BoundColumn DataField="IntegerValue"
SortExpression="IntegerValue"
HeaderText="Item"/> <asp:BoundColumn DataField="StringValue"
SortExpression="StringValue"
HeaderText="Description"/> <asp:BoundColumn DataField="CurrencyValue"
HeaderText="Price"
SortExpression="CurrencyValue"
DataFormatString="{0:c}"> <ItemStyle HorizontalAlign="Right">
</ItemStyle> </asp:BoundColumn> </Columns>
</asp:DataGrid>
</form>
</body>
</html>