code-beside方式绑定GridView后EnableSortingAndPagingCallbacks不工作

今天对GridView的学习中发现 当用 code-beside方式绑定GridView后(比如我绑一个DataTable)
EnableSortingAndPagingCallbacks不起作用。
在下面地址找到 一些说法

http://forums.asp.net/thread/1230450.aspx

http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=103040
记之...

 1 None.gif      < asp:GridView  id ="Gridviewex1"  
 2 None.gif    runat ="server"  
 3 None.gif    AllowSorting ="True"  
 4 None.gif    AutoGenerateColumns ="False"
 5 None.gif    EnableSortingAndPagingCallbacks ="True"  
 6 None.gif    OnSorting ="Gridviewex1_Sorting" >
 7 None.gif         < Columns >
 8 None.gif             < asp:BoundField  DataField ="ProductId"  HeaderText ="ProductId"  SortExpression ="ProductId"   />
 9 None.gif             < asp:BoundField  DataField ="ProductName"  HeaderText ="ProductName"  SortExpression ="ProductName"   />
10 None.gif             < asp:BoundField  DataField ="QuantityPerUnit"  HeaderText ="QuantityPerUnit"  SortExpression ="QuantityPerUnit"   />
11 None.gif             < asp:BoundField  DataField ="UnitsInStock"  HeaderText ="UnitsInStock"  SortExpression ="UnitsInStock"   />
12 None.gif             < asp:BoundField  DataField ="ReorderLevel"  HeaderText ="ReorderLevel"  SortExpression ="ReorderLevel"   />
13 None.gif             < asp:BoundField  DataField ="Discontinued"  HeaderText ="Discontinued"  SortExpression ="Discontinued"   />
14 None.gif         </ Columns >
15 None.gif     </ aspx:GridView >
 1 None.gif      protected   void  Page_Load( object  sender, EventArgs e)
 2 ExpandedBlockStart.gifContractedBlock.gif     dot.gif {
 3InBlock.gif
 4InBlock.gif        if (!Page.IsPostBack)
 5ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 6InBlock.gif            this.BindGrid(string.Empty);
 7ExpandedSubBlockEnd.gif        }

 8ExpandedBlockEnd.gif    }

 9 None.gif
10 None.gif     private   void  BindGrid( string  sortExpression)
11 ExpandedBlockStart.gifContractedBlock.gif     dot.gif {
12InBlock.gif        DataTable dt = new DataTable();
13InBlock.gif        SqlConnection conn = new SqlConnection();
14InBlock.gif        conn.ConnectionString = "server=wumeibo\\wmb;database=northwind;uid=sa;pwd=sa;";
15InBlock.gif        SqlCommand cmd = new SqlCommand();
16InBlock.gif        cmd.Connection = conn;
17InBlock.gif        cmd.CommandType = CommandType.Text;
18InBlock.gif        cmd.CommandText = "select * from products";
19InBlock.gif        SqlDataAdapter adapter = new SqlDataAdapter();
20InBlock.gif        adapter.SelectCommand = cmd;
21InBlock.gif        adapter.Fill(dt);
22InBlock.gif        DataView dv = dt.DefaultView;;
23InBlock.gif        if (!string.IsNullOrEmpty(sortExpression))        
24ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
25InBlock.gif            dv = dt.DefaultView;
26InBlock.gif            dv.Sort = sortExpression;
27ExpandedSubBlockEnd.gif        }

28InBlock.gif        this.Gridviewex1.DataSource = dv;
29InBlock.gif        this.Gridviewex1.DataBind();
30InBlock.gif        
31ExpandedBlockEnd.gif    }

32 None.gif     protected   void  Gridviewex1_Sorting( object  sender, GridViewSortEventArgs e)
33 ExpandedBlockStart.gifContractedBlock.gif     dot.gif {
34InBlock.gif        BindGrid(e.SortExpression);
35ExpandedBlockEnd.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      }

转载于:https://www.cnblogs.com/huobazi/archive/2006/07/03/EnableSortingAndPagingCallbacksIsNotWorkingWhenNotUseTheSqlDataSourceContorl.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值