This code is very succefully to me…
you can disable the command buttons on runtime conditionally… and enable or disable edit columns conditionally
best wishes
James
protected void ASPxGridViewRes_HtmlRowPrepared(object sender, ASPxGridViewTableRowEventArgs e)
{
int commandColumnIndex = -1;
for (int i = 0; i < (sender as ASPxGridView).Columns.Count; i++)
if ((sender as ASPxGridView).Columns[i] is GridViewCommandColumn)
{
commandColumnIndex = i;
break;
}
DevExpress.Web.ASPxGridView.Rendering.GridViewTableCommandCell cell = e.Row.Cells[commandColumnIndex] as DevExpress.Web.ASPxGridView.Rendering.GridViewTableCommandCell;
if (cell != null)
{
for (int i = 0; i < cell.Controls.Count; i++)
{
DevExpress.Web.ASPxGridView.Rendering.GridViewCommandColumnButtonControl button = cell.Controls[i] as DevExpress.Web.ASPxGridView.Rendering.GridViewCommandColumnButtonControl;
if (button == null) continue;
if (button.Text == "Edit")
{
if (***your condition**** )
{
DevExpress.Web.ASPxClasses.Internal.InternalHyperLink hyperlink = button.Controls[0] as DevExpress.Web.ASPxClasses.Internal.InternalHyperLink;
hyperlink.Enabled = true;
hyperlink.Text = "Edit";
}
else
{
DevExpress.Web.ASPxClasses.Internal.InternalHyperLink hyperlink = button.Controls[0] as DevExpress.Web.ASPxClasses.Internal.InternalHyperLink;
hyperlink.Enabled = false;
hyperlink.Text = "—";
}
}
}
}
}
protected void ASPxGridViewRes_CellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e)
{
if (e.Column.FieldName == "your column")
{
e.Editor.ReadOnly = false;
e.Editor.BackColor = System.Drawing.Color.Orange;
}
if (e.Column.FieldName == "another column")
if (" another condition")
{
e.Editor.ReadOnly = false;
e.Editor.BackColor = System.Drawing.Color.Orange;
}
}
Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.
Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.
Hi James,
Thank you for sharing your code with us. We will certainly create a tutorial project using a similar code and publish it at:
Tutorials
Thanks,
Plato
We've added a new CommandButtonInitialize event to make sure you are able to change command button controls visibility and disable/enable them easily.
The following example illustrates how to make every third "Select" button/link invisible and every second - disabled:
protected void ASPxGridView1_CommandButtonInitialize(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCommandButtonEventArgs e) {
if (e.Button.ButtonType != DevExpress.Web.ASPxGridView.ColumnCommandButtonType.Select) return;
e.Visible = e.VisibleIndex % 3 != 1;
e.Enabled = e.VisibleIndex % 2 != 1;
}
Thank you,
Andrew R&D.