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

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

以下是官方解决方案:

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 Then
                  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

原文地址:

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

版权说明:作者:张颖希PocketZ's Blog
出处:http://www.cnblogs.com/PocketZ
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
若本文为翻译内容,目的为练习英文水平,如有雷同,纯属意外!有不妥之处,欢迎拍砖

原文地址:https://www.cnblogs.com/PocketZ/p/1744707.html