Form View Problem
-
Hi All,
I’m following the examples at:
http://msconline.maconstate.edu/tutorials/aspnet20/ASPNET09/aspnet09-03.aspxhttp://msconline.maconstate.edu/tutorials/aspnet20/ASPNET09/aspnet09-04.aspx
to enable site users to insert edit and delete content. The insert edit and delete commands always lead to a syntax error in the Update/Insert statements or a stack trace error. I have tried different combinations but still have the same problem. From scanning my insert and update statements are exactly the same as the ones of the example sites, below is the code for the page I am trying to create:
<%@ Page Language="VB" MasterPageFile="iknowkungfu.master" AutoEventWireup="false" CodeFile="index.aspx.vb" Inherits="_default" title="Untitled Page" %>
<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<title>I Know Kung Fu :: News!</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"><div class="ikkfu-body-panel">
<div class="ikkfu-body-panel-header">
<div class="panel-header">
<asp:AccessDataSource
id="db"
datafile="iknowkungfudb.mdb"
selectcommand="select pagetitle from news"
runat="server" />
<asp:Repeater id="pagetitle" DataSourceID="db" Runat="server">
<itemTemplate>
<%#Eval("pagetitle")%>
</itemTemplate>
</asp:Repeater>
</div>
</div><div class="ikkfu-body-panel-body">
<div class="panel-body">
<asp:AccessDataSource
id="db1"
datafile="iknowkungfudb.mdb"
SelectCommand="SELECT * FROM news ORDER BY id DESC"
InsertCommand="INSERT news (title,content,date,time) values(@title,@content,@date,@time)"
UpdateCommand="UPDATE news SET title=@title, content=@content, date=@date, time=@time WHERE id = @id"
Runat="Server" />
<asp:Label id="EditMSG" Text=" " ForeColor="Red" Runat="Server" EnableViewState="False"/>
<asp:Panel ID="Panel1" Visible="False" EnableViewState="False" Runat="Server">
<asp:Label ID="Label1" Text="Delete this record? " ForeColor="Red" Runat="Server"/>
</asp:Panel><form runat="server">
<asp:FormView id="FormView" DataSourceID="db1" Runat="Server"
DataKeyNames="title"
OnItemInserting="Validate_Insert_Data"
OnItemInserted="Display_Insert_Msg"
OnItemUpdating="Validate_Update_Data"
OnItemUpdated="Display_Update_Msg"
OnItemDeleting="Confirm_Delete"
OnItemCommand="Get_Command"
AllowPaging="True"
GridLines="None">
<SCRIPT Runat="Server">'-- OnItemInserting --
Sub Validate_Insert_Data(ByVal Src As Object, ByVal Args As FormViewInsertEventArgs)If Args.Values("title") = "" Then
Args.Cancel = True
EditMSG.Text = "-- Missing title. Record not added."
End IfEnd Sub
'-- OnItemInserted --
Sub Display_Insert_Msg(ByVal Src As Object, ByVal Args As FormViewInsertedEventArgs)
EditMSG.Text = " Record " & Args.Values("title") & " added"
End Sub'-- OnItemUpdating --
Sub Validate_Update_Data(ByVal Src As Object, ByVal Args As FormViewUpdateEventArgs)End Sub
'-- OnItemUpdated --
Sub Display_Update_Msg(ByVal Src As Object, ByVal Args As FormViewUpdatedEventArgs)
EditMSG.Text = " Record " & Args.Keys("title") & " updated"
End Sub</SCRIPT>
<SCRIPT Runat="server">
Sub Confirm_Delete(ByVal Src As Object, ByVal Args As FormViewDeleteEventArgs)Args.Cancel = True
Dim ConfirmLabel As Label = FormView.FindControl("ConfirmDelete")
ConfirmLabel.Visible = True
ViewState("title") = Args.Keys("title")End Sub
Sub Get_Command(ByVal Src As Object, ByVal Args As FormViewCommandEventArgs)If Args.CommandName = "Yes" Then
db1.DeleteCommand = "DELETE FROM news" & _
"WHERE title = '" & ViewState("title") & "'"
db1.Delete()
EditMSG.Text = " Record " & ViewState("title") & " deleted"
End IfEnd Sub
</SCRIPT>
<itemTemplate>
<asp:Label id="ConfirmDelete" Visible="False" EnableViewState="False" Runat="Server">
<asp:Label ID="Label2" Text="Delete this News Article? " ForeColor="Red"
Runat="Server"/>
<asp:Button ID="Button6" Text="Yes" CommandName="Yes" Font-Size="8pt" Width="30px" Runat="Server"/>
<asp:Button ID="Button7" Text="No" CommandName="No" Font-Size="8pt" Width="30px" Runat="Server"/>
</asp:Label>
<div class="ikkfu-sub-panel-header">
<div class="sub-panel-header">
<%#Eval("title")%> - <%#Eval("date")%>
<asp:Button ID="Button3" CommandName="Edit" Text="Edit" Font-Size="9pt" Width="50" Runat="Server"/>
<asp:Button ID="Button4" CommandName="New" Text="New" Font-Size="9pt" Width="50" Runat="Server"/>
<asp:Button ID="Button5" CommandName="Delete" Text="Delete" Font-Size="9pt" Width="50" Runat="Server"/>
</div>
</div>
<div class="ikkfu-sub-panel-body">
<div class="sub-panel-body">
<%#Eval("content")%>
</asp:Panel>
</div>
<div class="ikkfu-sub-panel-footer">
<div class="sub-panel-footer">
<hr class="hr" />
Posted <%#Eval("date")%> at <%#Eval("time")%>
</div>
</div>
</div>
</itemTemplate>
<EditItemTemplate>
<div class="ikkfu-sub-panel-header">
<div class="sub-panel-header"><asp:TextBox id="EditTitle" Runat="Server"
Text='<%#Eval("title")%>'/>
<asp:Button ID="Button8" CommandName="Update" Text="Update" Font-Size="9pt"
Width="50" Runat="Server"/>
<asp:Button ID="Button9" CommandName="Cancel" Text="Cancel" Font-Size="9pt"
Width="50" Runat="Server"/></div>
</div>
<div class="ikkfu-sub-panel-body">
<div class="sub-panel-body">
<asp:TextBox id="EditContent" Runat="Server" Height="200px" Width="535px"
Text='<%#Eval("content")%>' TextMode="MultiLine" />
</div>
<div class="ikkfu-sub-panel-footer">
<div class="sub-panel-footer">
<hr class="hr" />
Posted
<asp:TextBox Readonly="true" width="65px" id="EditDate" Runat="Server"
Text='<%#Eval("date")%>'/>
at <asp:TextBox Readonly="true" width="65px" id="EditTime" Runat="Server"
Text='<%#Eval("time")%>'/>
</div>
</div>
</div>
</EditItemTemplate><InsertItemTemplate>
<div class="ikkfu-sub-panel-header">
<div class="sub-panel-header">
<asp:TextBox id="AddTitle" MaxLength="29" Runat="Server"
Text='<%#Eval("title")%>'/>
<asp:TextBox width="107px" readonly="true" id="TextBox1" Runat="Server"
Text='<%# Now()%>'/>
<asp:Button ID="Button10" CommandName="INSERT" Text="Submit" Font-Size="9pt"
Width="50" Runat="Server"/>
<asp:Button ID="Button11" CommandName="Cancel" Text="Cancel" Font-Size="9pt"
Width="50" Runat="Server"/>
</div>
</div>
<div class="ikkfu-sub-panel-body">
<div class="sub-panel-body">
<asp:TextBox id="AddContent" Runat="Server" Height="200px" Width="535px"
Text='<%#Eval("content")%>' TextMode="MultiLine" />
</div>
<div class="ikkfu-sub-panel-footer">
<div class="sub-panel-footer">
<hr class="hr" />
</div>
</div>
</div>
</InsertItemTemplate>
</asp:FormView>
</div>
<div class="ikkfu-body-panel-footer">
</div>
</div>
</div>
</form>
</asp:Content>Any help would be greatly appreciated, thanks in advance.
Post a reply
ASP.NET forum discussion
-
How to get Hotmail Contacts
by salihagenter (5 replies)
-
How to send fax using VB.net
by Jeffry Clyde (35 replies)
-
Difference between class and interface
by aladanh.go (47 replies)
-
How to Add Text in Footer of Gridview?
by arthurmarsh (5 replies)
-
Using FedEx Web Service to Calculcate Shipping Cost
by ravialen3782 (8 replies)
ASP.NET tutorials
- The Evolution of a Azure Web Application
- Protecting your ASP.NET Web API using OAuth2 and the Windows Azure Access Control Service
- Using HTML5 History in an ASP.NET MVC Site
- An Introduction to testing with the Model-View-Presenter pattern for Web Forms Development
- Improving Web Site Performance and Scalability while saving money
Quick links
Recent activity
- arif ahmad replied to How to receive data in web ...
- William Thompson replied to What is the name of the Win...
- Sameera Piyadigamage replied to Point of Sale Developers: H...
- Scott Carline replied to 4 x C# Developers for large...
- Rajendra Dhakal replied to Restore SQL Server text dat...
- cloud rainda replied to How to convert between TS f...
No one has replied yet! Why not be the first?
Sign in or Join us (it's free).