(转)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

posted @ 2010-05-26 20:10  pocketz  阅读(693)  评论(0编辑  收藏  举报