根据DataGrid绑定的列的SortException字段进行排序

ContractedBlock.gif ExpandedBlockStart.gif 为DataGrid的某字段进行排序
None.gif        protected void dg_UserInfo_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif{
InBlock.gif            labWrong.Text 
= "";
InBlock.gif
InBlock.gif            
if (ViewState["SortExpression"!= null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (ViewState["SortExpression"].ToString() == e.SortExpression.ToString())
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
string cSortExpression = "";
InBlock.gif                    
if (ViewState["SortExpression"].ToString().Length > 5)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        cSortExpression 
= ViewState["SortExpression"].ToString().Substring(ViewState["SortExpression"].ToString().Length - 5 - 1 , 5);
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
if (cSortExpression == " DESC")
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        ViewState[
"SortExpression"= e.SortExpression;
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        ViewState[
"SortExpression"= e.SortExpression + " DESC";
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    ViewState[
"SortExpression"= e.SortExpression;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                ViewState[
"SortExpression"= e.SortExpression;
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif
//绑定列表的选择项为未选择    
InBlock.gif
    dg_UserInfo.SelectedIndex = -1;
InBlock.gif
//绑定列表数据
InBlock.gif
            BindData_dg_UserInfo();
ExpandedBlockEnd.gif        }

ContractedBlock.gif ExpandedBlockStart.gif 绑定函数中的对应代码
None.gif//取出指定表的所有记录。
None.gif
            DataTable dtUserInfo = UserManage.GetAllUsers();
None.gif            
// sort the view according to the value stored in the ViewState, in any
None.gif
            DataView dvUserInfo = dtUserInfo.DefaultView;
None.gif            
if (ViewState["SortExpression"!= null)
None.gif                dvUserInfo.Sort 
= ViewState["SortExpression"].ToString();
None.gif            dg_UserInfo.DataSource 
= dvUserInfo;
None.gif            dg_UserInfo.DataBind();

转载于:https://www.cnblogs.com/hanguoji/archive/2006/11/28/574755.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值