DetailsView Update command doesn't update unless all of the fields are present!
I have a page that binds data from DB to a DetailsView.
I want to use the auto-generated Update command.
Everything went OK, and also updating was successful, but if I remove any field that I don't want to have chance to update, then the Update command doesn't update! the old values retain!
I开发者_如何学JAVA mean: if all of the fields are present in the detailsView, the update will be OK, otherwise, the update will NOT update any thing.
I've tried to mark the fields that I don't want to view as "Visible = 'false'" but with no good results!
How could I hide some fields?
Thanks :)
Did you try to put the field you don't want to update at 'ReadOnly = True' too? This should mark them as to not be updated.
Here is a way of doing it..
protected void DetailsView1_ModeChanged(object sender, EventArgs e)
{
if (DetailsView1.CurrentMode == DetailsViewMode.Edit)
{
foreach (DataControlField fd in DetailsView1.Fields)
{
BoundField tmp = fd as BoundField;
if (tmp != null)
if (tmp.DataField == "YourReadOnlyColumnName")
tmp.ReadOnly = true;
}
}
}
精彩评论