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;
           
            }

如图:

 

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

转载于:https://www.cnblogs.com/igozjj/archive/2009/06/27/1512217.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值