Earn Cash from forex trading and free 5$ for Regiatation.

Wednesday, December 3, 2008

Make a WebGrid cell read-only in certain conditions

Server-Side:

In the InitializeRow event, set AllowEditing property to "AllowEditing.No" after checking the condition. In this example, updates are forbidden for cells in the fourth column if the value is already greater than 5000:

private void UltraWebGrid1_InitializeRow(object sender, Infragistics.WebUI.UltraWebGrid.RowEventArgs e)
{
if ((int) e.Row.Cells[3].Value > 5000)
{
e.Row.Cells[3].AllowEditing = Infragistics.WebUI.UltraWebGrid.AllowEditing.No;
}
}



Client-Side:

Disable editing on the cell in the BeforeEnterEditMode client-side event handler by canceling the event (returning a value of "true") after checking the condition. In this example, updates are forbidden for cells that belong in the "Dept" column whose value is not "Finance":

In JavaScript:

function UltraWebGrid1_BeforeEnterEditModeHandler(gridName, cellId)
{
var c = igtbl_getCellById(cellId);

if (c.Column.Key == "Dept" && c.getValue() != "Finance")
{
return true;
}
}

0 comments: