locked
adding a field to the News_edit page RRS feed

  • Question

  • User1610544847 posted

    Hi

     I want to add a new field onto the News_edit.aspx page on the Club starter kit.  I have added the code that I though I needed to change but when I update the new field doesn't pass into the database. Am I missing something obvious or just being dumb

     The new field is a text field called 'music' 

     I've added it to the HTML
    I've added it to the SQL Insert and Update
    I've added it to the update Parameters

    Here's the code

     

    <%@ Page Language="VB" MasterPageFile="~/Default.master" Title="Edit News Article"

    ValidateRequest="false" %>

    <%@ Import Namespace="System.Data" %>

    <%@ Register TagPrefix="Club" Namespace="ClubSite" %>

    <%@ Register TagPrefix="Club" TagName="LoginBanner" Src="LoginBanner.ascx" %>

    <%@ Register TagPrefix="Club" TagName="ImageThumbnail" Src="ImageThumbnail.ascx" %>

    <%@ Register TagPrefix="Club" TagName="Photopicker" Src="photos_formpicker.ascx" %>

    <%@ Register TagPrefix="Club" TagName="Dateandtimepicker" Src="Dateandtimepicker.ascx" %>

    <%@ Register TagPrefix="Club" TagName="PhotoAlbumPicker" Src="photoalbum_picker.ascx" %>

    <%@ Register TagPrefix="FTB" Namespace="FreeTextBoxControls" Assembly="FreeTextBox" %>

    <script runat="server">

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

    If Not IsPostBack Then

    'Initialize the fields

     

    Dim action As Object = Request.QueryString("Action")

    If Not action Is Nothing Then

    If LCase(CStr(action)) = "new" Then

    FormView1.ChangeMode(FormViewMode.Insert)

    CType(FormView1.FindControl("dtpicker"), DateandTimePicker).selectedDateTime = Now

    CType(FormView1.FindControl("albumpick"), AlbumPicker).AlbumID = 0

    End If

    If LCase(CStr(action)) = "remove" Then

    SqlDataSource1.Delete()

    Response.Redirect("news_list.aspx")

    End If

    End If

     

    End If

    End Sub

    Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs)

    If FormView1.CurrentMode = FormViewMode.Insert Then

    CType(FormView1.FindControl("dtpicker"), DateandTimePicker).selectedDateTime = Now

    Else

    Dim cb As CheckBox = CType(FormView1.FindControl("CheckBox1"), CheckBox)

    Dim surl As TextBox = CType(FormView1.FindControl("staticURLTextBox"), TextBox)

    If surl.Text <> "" Then

    cb.Checked = True

    surl.Enabled = True

    Else

    surl.Enabled = False

    End If

     

    End If

    End Sub

    Protected Sub FormView1_ItemUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewUpdatedEventArgs)

    Response.Redirect("news_view.aspx?ArticleID=" & e.Keys("id").ToString)

    End Sub

     

    Protected Sub FormView1_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertedEventArgs)

    Response.Redirect("news_list.aspx")

    End Sub

    Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)

    Dim cb As CheckBox = CType(FormView1.FindControl("CheckBox1"), CheckBox)

    Dim surl As TextBox = CType(FormView1.FindControl("StaticURLTextBox"), TextBox)

    If cb.Checked Then

    surl.Enabled = True

    Else

    surl.Enabled = False

    End If

    End Sub

     

    Protected Sub AlbumList_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs)

    Dim param As Data.Common.DbParameter = e.Command.Parameters("@userid")

    param.DbType = Data.DbType.Guid

    If Page.User.Identity.IsAuthenticated Then

    param.Value = Membership.GetUser().ProviderUserKey

    Else

    param.Value = DBNull.Value

    End If

    End Sub

    Protected Sub LoginBanner1_Load(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub

    </script>

    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

    <div id="body">

    <Club:LoginBanner ID="LoginBanner1" runat="server" OnLoad="LoginBanner1_Load" />

    <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="id"

    DefaultMode="Edit" OnDataBound="FormView1_DataBound" OnItemUpdated="FormView1_ItemUpdated"

    OnItemInserted="FormView1_ItemInserted">

    <InsertItemTemplate>

    <div class="fullwidth">

    <h3>

    New News Article</h3>

    <div class="dashedline">

    </div>

    <div>

    <div class="actionbuttons">

    <Club:RolloverButton ID="GreenRolloverButton2" CommandName="Insert" Text="Save Article"

    runat="server" />

    <Club:RolloverLink ID="GreenRolloverLink1" Text="Cancel" runat="server" NavigateURL="news_list.aspx" />

    </div>

    </div>

    <div class="dashedline">

    </div>

    <table>

    <tr>

    <td class="formlabel">

    Article Title:

    </td>

    <td align="left">

    <asp:TextBox ID="titleTextBox" runat="server" Width="500px" Text='<%# Bind("title") %>'></asp:TextBox>

    </td>

    </tr>

    <tr>

    <td class="formlabel">

    Link:

    </td>

    <td align="left">

    <asp:CheckBox ID="CheckBox1" runat="server" Text="Use a link instead of inline content for this article."

    OnCheckedChanged="CheckBox1_CheckedChanged" AutoPostBack="true" /><br />

    URL:

    <asp:TextBox Text='<%# Bind("staticURL") %>' runat="server" ID="staticURLTextBox"

    Width="450px" />

    </td>

    </tr>

    <tr>

    <td class="formlabel">

    <asp:Label ID="Label1" runat="server" Text="Description:" />

    </td>

    <td align="left">

    <asp:TextBox Text='<%# Bind("description") %>' runat="server" ID="descriptionTextBox"

    Rows="10" TextMode="MultiLine" Width="500px" Height="166px"></asp:TextBox>

    </td>

    </tr>

    <tr>

    <td class="formlabel">

    Music Styles:

    </td>

    <td align="left">

    <asp:TextBox ID="TextBox1" runat="server" Width="500px" Text='<%# Bind("Music") %>'></asp:TextBox>

    </td>

    </tr>

    <tr>

    <td class="formlabel">

    Article Date</td>

    <td align="left">

    The news article will not be visible to users until after this date.

    <Club:Dateandtimepicker ID="dtpicker" runat="server" selectedDateTime='<%#Bind("itemdate") %>' />

    </td>

    </tr>

    <tr>

    <td class="formlabel">

    Photo:</td>

    <td align="left">

    <Club:Photopicker ID="Photopicker1" runat="server" ImageId='<%# Bind("photo") %>'

    SmallImage="true" />

    </td>

    </tr>

    <tr>

    <td class="formlabel">

    Photo Album</td>

    <td align="left">

    Optionally, the news article can be assoiated with a photo album.

    <br />

    <Club:PhotoAlbumPicker ID="albumpick" runat="server" AlbumID='<%# bind("Albumid") %>' />

    </td>

    </tr>

    </table>

    <div class="dashedline">

    </div>

    <div class="actionbuttons">

    <Club:RolloverButton ID="GreenRolloverButton3" CommandName="Insert" Text="Save Article"

    runat="server" />

    <Club:RolloverLink ID="GreenRolloverLink2" Text="Cancel" runat="server" NavigateURL="news_list.aspx" />

    </div>

     

     

    html Editor:- Use this control to make your HTML, once you are happy with your HTML, copy the source HTML to the decription box

    <FTB:FreeTextBox id="FreeTextBox1" BackColor="#ffffcc" runat="Server" />

    <div class="dashedline">

    </div>

    </div>

    </div>

    </InsertItemTemplate>

    <EditItemTemplate>

    <div class="fullwidth">

    <h3>

    Edit News Article</h3>

    <div class="dashedline">

    </div>

    <div class="actionbuttons">

    <Club:RolloverButton ID="GreenRolloverButton1" CommandName="Update" Text="Save Changes"

    runat="server" />

    <Club:RolloverLink ID="GreenRolloverLink3" Text="Cancel" runat="server" NavigateURL='<%# "news_view.aspx?ArticleID=" & Cstr(Eval("ID")) %>' />

    </div>

    <div class="dashedline">

    </div>

    <table>

    <tr>

    <td class="formlabel">

    Article Title:

    </td>

    <td align="left">

    <asp:TextBox ID="titleTextBox" runat="server" Width="500px" Text='<%# Bind("title") %>'></asp:TextBox>

    </td>

    </tr>

    <tr>

    <td class="formlabel">

    Link:

    </td>

    <td align="left">

    <asp:CheckBox ID="CheckBox1" runat="server" Text="Use a link instead of inline content for this article."

    OnCheckedChanged="CheckBox1_CheckedChanged" AutoPostBack="true" /><br />

    URL:

    <asp:TextBox Text='<%# Bind("staticURL") %>' runat="server" ID="staticURLTextBox"

    Width="450px" />

    </td>

    </tr>

    <tr>

    <td class="formlabel">

    <asp:Label ID="Label1" runat="server" Text="Description:" />

    </td>

    <td align="left">

    <asp:TextBox Text='<%# Bind("description") %>' runat="server" ID="descriptionTextBox"

    Rows="10" TextMode="MultiLine" Width="500px" Height="166px"></asp:TextBox>

    </td>

    </tr>

    <tr>

    <td class="formlabel">

    Music Styles:

    </td>

    <td align="left">

    <asp:TextBox ID="TextBox1" runat="server" Width="500px" Text='<%# Bind("Music") %>'></asp:TextBox>

    </td>

    </tr>

    <tr>

    <td class="formlabel">

    Article Date</td>

    <td align="left">

    <p>

    The news article will not be visible to users until after this date.

    </p>

    <Club:Dateandtimepicker ID="dtpicker" runat="server" selectedDateTime='<%#Bind("itemdate") %>' />

    </td>

    </tr>

    <tr>

    <td class="formlabel">

    Photo:</td>

    <td align="left">

    <Club:Photopicker ID="Photopicker1" runat="server" ImageId='<%# Bind("photo") %>'

    SmallImage="true" />

    </td>

    </tr>

    <tr>

    <td class="formlabel">

    Photo Album</td>

    <td align="left">

    <p>

    Optionally, the news article can be assoiated with a photo album.

    </p>

    <Club:PhotoAlbumPicker ID="albumpick" runat="server" AlbumID='<%# bind("Albumid") %>' />

    </td>

    </tr>

    </table>

    <div class="dashedline">

    </div>

    <div class="actionbuttons">

    <Club:RolloverButton ID="apply1" CommandName="Update" Text="Save Changes" runat="server" />

    <Club:RolloverLink ID="Cancel" Text="Cancel" runat="server" NavigateURL='<%# "news_view.aspx?ArticleID=" & Cstr(Eval("ID")) %>' />

    </div>

     

     

    html Editor:- Use this control to make your HTML, once you are happy with your HTML, copy the source HTML to the decription box

    <FTB:FreeTextBox id="FreeTextBox1" BackColor="#ffffcc" runat="Server" />

    <div class="dashedline">

    </div>

    </div>

    </div>

    </EditItemTemplate>

    </asp:FormView>

    </div>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ClubSiteDB %>"

    SelectCommand="SELECT id, itemdate, title, description, staticURL, photo, albumid, music from announcements where Announcements.id=@id"

    InsertCommand="INSERT INTO Announcements(itemdate, title, description, staticURL, photo, albumid) VALUES (@itemdate, @title, @description, @staticURL, @photo, @albumid, @music)"

    UpdateCommand="UPDATE Announcements SET itemdate = @itemdate, title = @title, description = @description, staticURL = @staticURL, photo = @photo, albumid = @albumid, music@music WHERE (id = @id)"

    DeleteCommand="Delete from Announcements where id=@id" OldValuesParameterFormatString="{0}">

    <SelectParameters>

    <asp:QueryStringParameter Name="id" QueryStringField="ArticleID" />

    </SelectParameters>

    <UpdateParameters>

    <asp:Parameter Name="itemdate" Type="DateTime" />

    <asp:Parameter Name="title" />

    <asp:Parameter Name="description" />

    <asp:Parameter Name="staticURL" />

    <asp:Parameter Name="location" />

    <asp:Parameter Name="photo" />

    <asp:Parameter Name="id" />

    <asp:Parameter Name="albumid" />

    <asp:Parameter Name="music" />

    </UpdateParameters>

    <InsertParameters>

    <asp:Parameter Name="itemdate" Type="DateTime" />

    <asp:Parameter Name="title" />

    <asp:Parameter Name="description" />

    <asp:Parameter Name="staticURL" />

    <asp:Parameter Name="location" />

    <asp:Parameter Name="photo" />

    <asp:Parameter Name="id" />

    <asp:Parameter Name="albumid" />

    <asp:Parameter Name="music" />

    </InsertParameters>

    <DeleteParameters>

    <asp:QueryStringParameter Name="id" QueryStringField="ArticleID" />

    </DeleteParameters>

    </asp:SqlDataSource>

    <asp:SqlDataSource ConnectionString="<%$ ConnectionStrings:ClubSiteDB %>" ID="AlbumList"

    runat="server" SelectCommand="AlbumList" SelectCommandType="StoredProcedure"

    OnSelecting="AlbumList_Selecting">

    <SelectParameters>

    <asp:Parameter Name="userid" />

    </SelectParameters>

    </asp:SqlDataSource>

    </asp:Content>

     

    Wednesday, January 10, 2007 9:59 AM

Answers

  • User-80939892 posted

    In your UpdateCommand there is a typo... music@music  (see highlighted text below)

     

    UpdateCommand="UPDATE Announcements SET itemdate = @itemdate, title = @title, description = @description, staticURL = @staticURL, photo = @photo, albumid = @albumid, music@music WHERE (id = @id)"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 11, 2007 1:48 PM