有时我们需要在程序运行时让某些用户对某些记录没有修改的权限,只能查看,但有的记录又有修改的权限,此时就需要在运行的时候来设定命令行的按钮情况,
以下是官方解决方案:
[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;
}
如图:
方法比较笨,不过能实现其功能,见笑了