EnableSortingAndPagingCallbacks不起作用。
在下面地址找到 一些说法
http://forums.asp.net/thread/1230450.aspx
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=103040
记之...
1
<
asp:GridView
id
="Gridviewex1"
2
runat
="server"
3
AllowSorting
="True"
4
AutoGenerateColumns
="False"
5
EnableSortingAndPagingCallbacks
="True"
6
OnSorting
="Gridviewex1_Sorting"
>
7
<
Columns
>
8
<
asp:BoundField
DataField
="ProductId"
HeaderText
="ProductId"
SortExpression
="ProductId"
/>
9
<
asp:BoundField
DataField
="ProductName"
HeaderText
="ProductName"
SortExpression
="ProductName"
/>
10
<
asp:BoundField
DataField
="QuantityPerUnit"
HeaderText
="QuantityPerUnit"
SortExpression
="QuantityPerUnit"
/>
11
<
asp:BoundField
DataField
="UnitsInStock"
HeaderText
="UnitsInStock"
SortExpression
="UnitsInStock"
/>
12
<
asp:BoundField
DataField
="ReorderLevel"
HeaderText
="ReorderLevel"
SortExpression
="ReorderLevel"
/>
13
<
asp:BoundField
DataField
="Discontinued"
HeaderText
="Discontinued"
SortExpression
="Discontinued"
/>
14
</
Columns
>
15
</
aspx:GridView
>
![None.gif](/Images/OutliningIndicators/None.gif)
2
![None.gif](/Images/OutliningIndicators/None.gif)
3
![None.gif](/Images/OutliningIndicators/None.gif)
4
![None.gif](/Images/OutliningIndicators/None.gif)
5
![None.gif](/Images/OutliningIndicators/None.gif)
6
![None.gif](/Images/OutliningIndicators/None.gif)
7
![None.gif](/Images/OutliningIndicators/None.gif)
8
![None.gif](/Images/OutliningIndicators/None.gif)
9
![None.gif](/Images/OutliningIndicators/None.gif)
10
![None.gif](/Images/OutliningIndicators/None.gif)
11
![None.gif](/Images/OutliningIndicators/None.gif)
12
![None.gif](/Images/OutliningIndicators/None.gif)
13
![None.gif](/Images/OutliningIndicators/None.gif)
14
![None.gif](/Images/OutliningIndicators/None.gif)
15
![None.gif](/Images/OutliningIndicators/None.gif)
1
protected
void
Page_Load(
object
sender, EventArgs e)
2![ExpandedBlockStart.gif](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
3![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
4
if (!Page.IsPostBack)
5![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
6
this.BindGrid(string.Empty);
7
}
8
}
9![None.gif](/Images/OutliningIndicators/None.gif)
10
private
void
BindGrid(
string
sortExpression)
11![ExpandedBlockStart.gif](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
12
DataTable dt = new DataTable();
13
SqlConnection conn = new SqlConnection();
14
conn.ConnectionString = "server=wumeibo\\wmb;database=northwind;uid=sa;pwd=sa;";
15
SqlCommand cmd = new SqlCommand();
16
cmd.Connection = conn;
17
cmd.CommandType = CommandType.Text;
18
cmd.CommandText = "select * from products";
19
SqlDataAdapter adapter = new SqlDataAdapter();
20
adapter.SelectCommand = cmd;
21
adapter.Fill(dt);
22
DataView dv = dt.DefaultView;;
23
if (!string.IsNullOrEmpty(sortExpression))
24![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
25
dv = dt.DefaultView;
26
dv.Sort = sortExpression;
27
}
28
this.Gridviewex1.DataSource = dv;
29
this.Gridviewex1.DataBind();
30
31
}
32
protected
void
Gridviewex1_Sorting(
object
sender, GridViewSortEventArgs e)
33![ExpandedBlockStart.gif](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
34
BindGrid(e.SortExpression);
35
}
![None.gif](/Images/OutliningIndicators/None.gif)
2
![ExpandedBlockStart.gif](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](/Images/OutliningIndicators/ContractedBlock.gif)
![dot.gif](/Images/dot.gif)
3
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
4
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
5
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](/Images/dot.gif)
6
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
7
![ExpandedSubBlockEnd.gif](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
8
![ExpandedBlockEnd.gif](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
9
![None.gif](/Images/OutliningIndicators/None.gif)
10
![None.gif](/Images/OutliningIndicators/None.gif)
11
![ExpandedBlockStart.gif](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](/Images/OutliningIndicators/ContractedBlock.gif)
![dot.gif](/Images/dot.gif)
12
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
13
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
14
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
15
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
16
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
17
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
18
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
19
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
20
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
21
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
22
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
23
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
24
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](/Images/dot.gif)
25
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
26
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
27
![ExpandedSubBlockEnd.gif](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
28
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
29
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
30
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
31
![ExpandedBlockEnd.gif](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
32
![None.gif](/Images/OutliningIndicators/None.gif)
33
![ExpandedBlockStart.gif](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](/Images/OutliningIndicators/ContractedBlock.gif)
![dot.gif](/Images/dot.gif)
34
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
35
![ExpandedBlockEnd.gif](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
经过测试 如下方法 可用
1
protected
void
Page_Load(
object
sender, EventArgs e)
2 {
3 xx();
4
5 }
6
7 private void xx()
8 {
9 SqlConnection conn = new SqlConnection();
10 conn.ConnectionString = " server=wumeibo\\wmb;database=northwind;uid=sa;pwd=sa; " ;
11
12 SqlDataSource source = new SqlDataSource();
13 source.ConnectionString = " server=wumeibo\\wmb;database=northwind;uid=sa;pwd=sa; " ;
14 source.SelectCommand = " select * from products " ;
15
16 this .Gridviewex1.DataSource = source;
17 this .Gridviewex1.DataBind();
18 }
2 {
3 xx();
4
5 }
6
7 private void xx()
8 {
9 SqlConnection conn = new SqlConnection();
10 conn.ConnectionString = " server=wumeibo\\wmb;database=northwind;uid=sa;pwd=sa; " ;
11
12 SqlDataSource source = new SqlDataSource();
13 source.ConnectionString = " server=wumeibo\\wmb;database=northwind;uid=sa;pwd=sa; " ;
14 source.SelectCommand = " select * from products " ;
15
16 this .Gridviewex1.DataSource = source;
17 this .Gridviewex1.DataBind();
18 }