Don't try to change the mode of the formview by setting the DefaultView
property, instead use the ChangeMode method as follows:
FormView.ChangeMode(FormViewMode.Edit);
or
FormView.ChangeMode(FormViewMode.Insert);
or
FormView.ChangeMode(FormViewMode.ReadOnly);
"Dabbler" wrote:
> I have a calendar control and a formview control on the same page. Based on
> wether I have data for the calendar day of the SelectionChanged event, I want
> to change the FormView to the correct mode, insert or edit. I can't figure
> out how to make this happen and am not sure when I should set the FormView
> mode and rebind it.
>
> Thanks for any help on this.
>
> protected void calRideCounts_selectionChanged( object sender, EventArgs e ) {
> FillRideCountsDataset();
> bool found = false;
> if ( dsRideCounts != null && dsRideCounts.Tables.Count > 0 ) {
> foreach ( DataRow dr in dsRideCounts.Tables[0].Rows ) {
> DateTime rideDate = (DateTime)dr["RideDate"];
> if ( rideDate == calRideCounts.SelectedDate ) {
> // need to set FormView from insert to edit mode
> found = true;
> }
> }
> }
> DateTime dt = calRideCounts.SelectedDate;
> if ( found ) {
> fvRideCounts.DefaultMode = FormViewMode.Edit;
> fvRideCounts.DataBind();
> }
>
> TextBox tb = (TextBox)fvRideCounts.FindControl( "tbRideDate" );
> tb.Text = String.Format( "{0:MMMM dd}", dt );
> }
>
|