Home Page
Survey Builder
Form Builder
.NET Tools
.NET Articles
.NET Services
Product FAQ
Contact Form
Index
>
ASP.NET Web Applications
> How to use one FormView template as the InsertI...
ASP.NET Web Applications: FormView
How to use one FormView template as the InsertItemTemplate and EditItemTemplate
Typically, it is unnecessary to use two different form templates for update and insert operations. The following code snippet demonstrates how to force the FormView control to use a single template for inserts and updates.
Added on 9 Jul 2008
General Solutions:
Solution Summary:
Create either an InsertItemTemplate or an EditItemTemplate and, in the FormView's Init event, set the template which was not created equal to the one that was created.
Solution Details:
' The EditItemTemplate was defined in the ASPX page, and the InserItemTemplate was not
Protected
Sub
FormView1_Init(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
FormView1.Init
If
Not
IsPostBack
Then
FormView1.InsertItemTemplate = FormView1.EditItemTemplate
End
If
End
Sub
Change the submission button's command name and text to match the type of form currently selected:
Protected
Sub
FormView1_DataBound(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
FormView1.DataBound
' set update button
Dim
UpdateButton
As
Button =
CType
(sender.FindControl(
"UpdateButton"
), Button)
If
FormView1.CurrentMode = FormViewMode.Insert
Then
UpdateButton.Text =
"Add"
UpdateButton.CommandName =
"Insert"
Else
UpdateButton.Text =
"Update"
UpdateButton.CommandName =
"Update"
End
If
End
Sub
Was this solution useful?
Yes
No
Added on 9 Jul 2008
Rating:
Copyright 2010 © E-Centric, Inc. |
Terms of Use