Click to See Complete Forum and Search --> : Setting Default View In DetailsView


Scott.Macmaster
January 5th, 2009, 11:33 AM
I have a couple checkboxes in my DetailView that I want to default to checked when the user clicks insert. I can't find a option to set the default value. So I'm trying to do this using a template field. I then added this code to check the box when the mode changed event fires.


Protected Sub DetailsView_ModeChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DetailsView.ModeChanged

If DetailsView.CurrentMode = DetailsViewMode.Insert Then
' doesn't work
Dim optBooleanOption = CType(DetailsView.FindControl("optBooleanOption"), CheckBox)
optBooleanOption.Checked = True
' works
Dim lblBooleanOption = CType(DetailsView.FindControl("lblBooleanOption"), CheckBox)
optBooleanOption.Text = "test"
End If
End Sub


For some reason the check box control isn't in the control tree but the label control from ItemTemplate is. Interestingly, if I change the function to do something when the mode changes back to ReadOnly it can find the check box but not the label.

It seems like it hasn't rebuilt the control tree to reflect the new mode. I would have thought it would have done that before it calls ModeChanged. How can I get this to work?


Thanks,