If you decorate a dx:GridViewDataColumn with ReadOnly="true" at the .aspx or .ascx markup the form field one sees when inline editing with still be a form field of a type="text" shape with readonly slapped upon it. These uneditable fields do not read as uneditable to the eye. Wouldn't it be best to have a label instead of a disabled input? Yes. First use this event:
MyGrid.HtmlRowPrepared += MyGrid_HtmlRowPrepared;
...and then give the event some code to swap out the readonly input fields:
private void MyGrid_HtmlRowPrepared(object sender,
ASPxGridViewTableRowEventArgs e)
{
if(e.RowType.Equals(GridViewRowType.InlineEdit))
{
ASPxTextBox usernameControl = (ASPxTextBox)e.Row.Cells[0].Controls[0];
ASPxDateEdit lastLoginControl = (ASPxDateEdit)e.Row.Cells[7].Controls[0];
usernameControl.Visible = false;
lastLoginControl.Visible = false;
ASPxLabel userNameLabel = new ASPxLabel();
userNameLabel.Value = usernameControl.Value;
userNameLabel.CssClass = "whatever";
e.Row.Cells[0].Controls.Add(userNameLabel);
ASPxLabel lastLoginLabel = new ASPxLabel();
lastLoginLabel.Value = String.Format("{0:M/d/yyyy}", lastLoginControl.Value);
lastLoginLabel.CssClass = "whatever";
e.Row.Cells[7].Controls.Add(lastLoginLabel);
}
}
...dropping the username which is also the KeyFieldName came with some consequence. Stuff like this at the RowUpdating...
foreach (User user in _users.Where(user => user.Username ==
e.OldValues[0].ToString())) {
...had to be reshaped like so:
foreach (User user in _users.Where(user => user.Username == e.Keys[0].ToString())) {
No comments:
Post a Comment