ok i got those buttons on form view control but now i am getting following error
i wanted to enter first and last name to enter by user and update table attached.
FormView 'FormView1' must be in insert mode to insert a new record.
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: FormView 'FormView1' must be in insert mode to insert a new record.
// Iterate through the items in the Values collection
// and verify that the user entered a value for each
// text box displayed in the insert item template. Cancel
// the insert operation if the user left a text box empty.
foreach (DictionaryEntry entry in e.Values)
{
if (entry.Value.Equals(""))
{
// Use the Cancel property to cancel the
// insert operation.
e.Cancel = true;
MessageLabel.Text += "Please enter a value for the " +
entry.Key.ToString() + " field.<br/>";
}
}
}
void employeeformview_ModeChanged(Object sender, EventArgs e)
{
// Clear the MessageLabel Label control when the FormView
// control changes modes.
MessageLabel.Text = "";
}
As far as I see,I think you should generate CRUD methods for your FormView and enable Inserting,Updating and deleting。Then when you choose to click "Insert",it should automatically change the mode state to Insert。
Truptir
Member
10 Points
69 Posts
FormView Does not have public property linkbutton
Apr 07, 2012 01:07 PM|LINK
i am trying formview control example but getting error as
FormView Does not have public property linkbutton
my code is as below:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>FormView InsertItemTemplate Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>FormView InsertItemTemplate Example</h3>
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1"
AllowPaging="True">
<EditItemTemplate>
FirstName:
<asp:TextBox ID="FirstNameTextBox" runat="server"
Text='<%# Bind("FirstName") %>' />
<br />
LastName:
<asp:TextBox ID="LastNameTextBox" runat="server"
Text='<%# Bind("LastName") %>' />
<br />
Title:
<asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("Title") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
FirstName:
<asp:TextBox ID="FirstNameTextBox" runat="server"
Text='<%# Bind("FirstName") %>' />
<br />
LastName:
<asp:TextBox ID="LastNameTextBox" runat="server"
Text='<%# Bind("LastName") %>' />
<br />
Title:
<asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("Title") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
FirstName:
<asp:Label ID="FirstNameLabel" runat="server" Text='<%# Bind("FirstName") %>' />
<br />
LastName:
<asp:Label ID="LastNameLabel" runat="server" Text='<%# Bind("LastName") %>' />
<br />
Title:
<asp:Label ID="TitleLabel" runat="server" Text='<%# Bind("Title") %>' />
<br />
</ItemTemplate>
<asp:linkbutton id="InsertButton"
text="Insert"
commandname="Insert"
runat="server" />
<asp:linkbutton id="CancelButton"
text="Cancel"
commandname="Cancel"
runat="server" />
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:masterConnectionString %>"
SelectCommand="SELECT [FirstName], [LastName], [Title] FROM [Employees]"
insertcommand="Insert Into [Employees] ([LastName], [FirstName], [Title]) VALUES (@LastName, @FirstName, @Title)">
</asp:SqlDataSource>
</form>
</body>
</html>
mm10
Contributor
6445 Points
1187 Posts
Re: FormView Does not have public property linkbutton
Apr 07, 2012 01:22 PM|LINK
You need to put your Insert- and CancelButton inside the ItemTemplate:
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1"
AllowPaging="True">
<EditItemTemplate>
FirstName:
<asp:TextBox ID="FirstNameTextBox" runat="server"
Text='<%# Bind("FirstName") %>' />
<br />
LastName:
<asp:TextBox ID="LastNameTextBox" runat="server"
Text='<%# Bind("LastName") %>' />
<br />
Title:
<asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("Title") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
FirstName:
<asp:TextBox ID="FirstNameTextBox" runat="server"
Text='<%# Bind("FirstName") %>' />
<br />
LastName:
<asp:TextBox ID="LastNameTextBox" runat="server"
Text='<%# Bind("LastName") %>' />
<br />
Title:
<asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("Title") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
FirstName:
<asp:Label ID="FirstNameLabel" runat="server" Text='<%# Bind("FirstName") %>' />
<br />
LastName:
<asp:Label ID="LastNameLabel" runat="server" Text='<%# Bind("LastName") %>' />
<br />
Title:
<asp:Label ID="TitleLabel" runat="server" Text='<%# Bind("Title") %>' />
<br />
<asp:linkbutton id="InsertButton"
text="Insert"
commandname="Insert"
runat="server" />
<asp:linkbutton id="CancelButton"
text="Cancel"
commandname="Cancel"
runat="server" />
</ItemTemplate>
</asp:FormView>
Truptir
Member
10 Points
69 Posts
Re: FormView Does not have public property linkbutton
Apr 07, 2012 01:29 PM|LINK
ok i got those buttons on form view control but now i am getting following error
i wanted to enter first and last name to enter by user and update table attached.
FormView 'FormView1' must be in insert mode to insert a new record.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: FormView 'FormView1' must be in insert mode to insert a new record.
Truptir
Member
10 Points
69 Posts
Re: FormView Does not have public property linkbutton
Apr 07, 2012 04:26 PM|LINK
what a dumb question i've asked before!!anyway i wrote services for linked button in script tag but cancel command is not working
it should be ideally cancel the insert if all the textboxes are not filled but it is taking incompeted input.
code is as below (this code is same as it is provided in online example.)
<script runat="server">
void employeeformview_ItemInserting(Object sender, FormViewInsertEventArgs e)
{
MessageLabel.Text = "";
// Iterate through the items in the Values collection
// and verify that the user entered a value for each
// text box displayed in the insert item template. Cancel
// the insert operation if the user left a text box empty.
foreach (DictionaryEntry entry in e.Values)
{
if (entry.Value.Equals(""))
{
// Use the Cancel property to cancel the
// insert operation.
e.Cancel = true;
MessageLabel.Text += "Please enter a value for the " +
entry.Key.ToString() + " field.<br/>";
}
}
}
void employeeformview_ModeChanged(Object sender, EventArgs e)
{
// Clear the MessageLabel Label control when the FormView
// control changes modes.
MessageLabel.Text = "";
}
</script>
mm10
Contributor
6445 Points
1187 Posts
Re: FormView Does not have public property linkbutton
Apr 07, 2012 04:41 PM|LINK
So you mean the record gets inserted into the database despite there are some blank values?
Truptir
Member
10 Points
69 Posts
Re: FormView Does not have public property linkbutton
Apr 07, 2012 06:55 PM|LINK
yes they are getting inserted despite there are some blank values (and even though i've not specified NULL allow in table definition)
mm10
Contributor
6445 Points
1187 Posts
Re: FormView Does not have public property linkbutton
Apr 07, 2012 07:16 PM|LINK
Set a breakpoint inside your employeeformview_ItemInserting event to find out if there are any blank values being posted.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: FormView Does not have public property linkbutton
Apr 09, 2012 02:16 AM|LINK
Hello Truptir:)
As far as I see,I think you should generate CRUD methods for your FormView and enable Inserting,Updating and deleting。Then when you choose to click "Insert",it should automatically change the mode state to Insert。
See my sample at CodePlex:http://code.msdn.microsoft.com/Uploadedit-image-in-ASPNET-b96367a9