Form View Problem

asp.net South Africa
  • 10 years ago

    Hi All,


    I’m following the examples at:


    http://msconline.maconstate.edu/tutorials/aspnet20/ASPNET09/aspnet09-03.aspx

    http://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="&nbsp;" 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 If

                                             End 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 If

                  End 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"/>&nbsp;
                                                          &nbsp;
        
               </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

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Linux is only free if your time has no value” - Jamie Zawinski