• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
边缘软件
博客园    首页    新随笔    联系   管理    订阅  订阅

aspxgridview运行时设计命令列的按钮

有时我们需要在程序运行时让某些用户对某些记录没有修改的权限,只能查看,但有的记录又有修改的权限,此时就需要在运行的时候来设定命令行的按钮情况,

以下是官方解决方案:

 

[VB.NET]

Protected Sub ASPxGridView1_HtmlRowCreated(ByVal sender As Object, ByVal e AsDevExpress.Web.ASPxGridView.ASPxGridViewTableRowEventArgs) HandlesASPxGridView1.HtmlRowCreated
        If Not e.RowType = GridViewRowType.Data Then
            Exit Sub
        End If
        Try
            Dim cmdColumnIndex As Integer
            cmdColumnIndex = -1
            Dim cell AsDevExpress.Web.ASPxGridView.Rendering.GridViewTableCommandCell

            For inti As Integer = 0 To ASPxGridView1.Columns.Count - 1
                If TypeOf ASPxGridView1.Columns(inti) Is GridViewCommandColumnThen
                    cmdColumnIndex = inti
                    Exit For
                End If
            Next
            If cmdColumnIndex = -1 Then
                Return
            End If
            cell = TryCast(e.Row.Cells(cmdColumnIndex + ASPxGridView1.GroupCount), DevExpress.Web.ASPxGridView.Rendering.GridViewTableCommandCell)
            If cell Is Nothing Then
                Exit Sub
            End If


            For i As Integer = 0 To cell.Controls.Count - 1
                Dim Button AsDevExpress.Web.ASPxGridView.Rendering.GridViewCommandColumnButtonControl
                Button = cell.Controls(i)
                If Button.Button.ButtonType = ColumnCommandButtonType.Edit Then
                    Button.Visible = False
                    Select Case e.KeyValue Mod 2
                        ' Removed for development Launch of page.
                        Case 0
                            Button.Visible = True
                        Case Else
                            Button.Visible = False
                    End Select
                End If
            Next

        Catch Ex As Exception

            Throw Ex
        End Try
    End Sub

Thanks,
Plato

原文地址:

http://www.devexpress.com/Support/Center/p/B92220.aspx

偶根据所需改成了自已的c#

   void Aspxgrid_HtmlRowCreated(object sender, ASPxGridViewTableRowEventArgs e)
        {

            if (e.RowType != GridViewRowType.Data)
                return;

            try
            {

                int cmdColumnIndex = -1;
                DevExpress.Web.ASPxGridView.Rendering.GridViewTableCommandCell cell;

                for (int i = 0; i < Aspxgrid.Columns.Count-1; i++)
                {

                    if (Aspxgrid.Columns[i] is GridViewCommandColumn)
                        cmdColumnIndex = i;


                }

                if (cmdColumnIndex == -1)
                    return;

               // cell = TryCast(e.Row.Cells(cmdColumnIndex + ASPxGridView1.GroupCount), DevExpress.Web.ASPxGridView.Rendering.GridViewTableCommandCell)
                cell = (DevExpress.Web.ASPxGridView.Rendering.GridViewTableCommandCell)e.Row.Cells[cmdColumnIndex + Aspxgrid.GroupCount];
                if (cell is Nullable) return;

                for (int i = 0; i < cell.Controls.Count-1; i++)
                {
                    DevExpress.Web.ASPxGridView.Rendering.GridViewCommandColumnButtonControl button = cell.Controls[i] as DevExpress.Web.ASPxGridView.Rendering.GridViewCommandColumnButtonControl ;
                
                   
                   
                  //  if (button.Button.ButtonType == ColumnCommandButtonType.Edit && !isadmin(e.GetValue("falltschool").ToString()))  此语得不到button.Button.ButtonType 这个子属性,所以只能改成这样
                    if ((button.Text.Trim() == "编辑" || button.Text.Trim() == "删除") && !ispower(e.GetValue("falltschool").ToString()))
                    {

                        button.Visible = false;

                    }
                    else
                        button.Visible = true;
                }

            }
            catch (Exception ex)
            {

                throw ex;
           
            }

如图:

 

方法比较笨,不过能实现其功能,见笑了

posted @ 2009-06-27 13:45  边缘软件  阅读(684)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3