Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 4th, 2006, 05:10 PM
Friend of Wrox
Join Date: Oct 2005
Posts: 173
Thanks: 0
Thanked 2 Times in 1 Post
Default Dynamically Controlling DefaultMode of Formview

Hi All

Me again, I have another question in my journey within ASP.Net2..

I can see what I want to do but at the moment can't see how to achieve it..

I have a Formview control that is databound. What I would like to be able to do is to dynamically set the DefaultMode of the formview depending on the whether the SQLDataSource is full or empty.. ie.

If Empty DefaultMode="Insert" other DefaultMode="Edit".

The way I thought I could acheive this is using the Page_Load event that checks the SQLDataSource and then sets the DefaultMode of the formview.

.. Does this sound right?.. if so how would I be able to check the status of the SQLDataSource?


Old February 4th, 2006, 07:57 PM
Imar's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

I think what you need is the ChangeMode method of the FormView class: http://msdn2.microsoft.com/system.we...hangemode.aspx

This method allows you to switch the FormView from one mode to another. The DefaultMode is just, euh, the Default. It has always surprised me a bit that it's called the DefaultMode, and not just the Mode property that allows you to switch by simply changing the property's value....

Imar Spaanjaars
Everyone is unique, except for me.
Old February 15th, 2006, 07:16 PM
Friend of Wrox
Join Date: Oct 2005
Posts: 173
Thanks: 0
Thanked 2 Times in 1 Post

Hi All

If anyone is wondering how to check if a formview is empty before dynamically change the mode, I used this:

Protected Sub FormView1_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs)
        If FormView1.DataItemCount < 1 Then
        End If
    End Sub
.. it seems to work.


Similar Threads
Thread Thread Starter Forum Replies Last Post
controlling frames dynamically parameswaranvv Javascript How-To 1 April 9th, 2008 05:30 AM
Controlling a Windows Service sajid08 C# 1 October 30th, 2006 04:53 AM
Controlling Print with Javascript arnabghosh Javascript How-To 1 August 10th, 2005 08:21 AM
Controlling InternetExplorer jamie_t VB How-To 2 March 15th, 2005 07:22 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.