DetailsView not updating

Discussion in 'ASP .Net' started by David Lozzi, Jan 5, 2007.

  1. David Lozzi

    David Lozzi Guest

    Howdy,

    I have a DetailsView that when I fire the UpdateItem event, it doesn't
    update the data. The page reloads and the data is set back to the original.
    I'm using a Button to fire the UpdateItem event and then leaves the user a
    status stating that the event is updated, which does occur so i know the
    button is firing properly. I haven't tried InsertItem yet, going to set that
    up now. Any ideas why this is happening? My code is below.

    Thanks
    David Lozzi

    <asp:DetailsView ID="dvDetails" runat="server" AutoGenerateRows="False"
    DataSourceID="SqlDataSource1" BorderWidth="0px" DefaultMode="Edit">

    <Fields>

    <asp:BoundField DataField="strTitle" HeaderText="Title"
    SortExpression="strTitle" />

    <asp:TemplateField HeaderText="strDescription"
    SortExpression="strDescription">

    <EditItemTemplate>

    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("strDescription")
    %>' Columns="60" Rows="3" TextMode="MultiLine"></asp:TextBox>

    </EditItemTemplate>

    <InsertItemTemplate>

    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("strDescription")
    %>' Columns="60" Rows="3" TextMode="MultiLine"></asp:TextBox>

    </InsertItemTemplate>

    <ItemTemplate>

    <asp:Label ID="Label1" runat="server" Text='<%# Bind("strDescription")
    %>'></asp:Label>

    </ItemTemplate>

    </asp:TemplateField>

    <asp:BoundField DataField="dtDate" HeaderText="Date" SortExpression="dtDate"
    />

    <asp:BoundField DataField="strSpeaker" HeaderText="Speaker"
    SortExpression="strSpeaker" />

    <asp:BoundField DataField="strHost" HeaderText="Host"
    SortExpression="strHost" />

    <asp:BoundField DataField="strLocation" HeaderText="Location"
    SortExpression="strLocation" />

    <asp:BoundField DataField="strAddress" HeaderText="Address"
    SortExpression="strAddress" />

    <asp:BoundField DataField="strCity" HeaderText="City"
    SortExpression="strCity" />

    <asp:BoundField DataField="strState" HeaderText="State"
    SortExpression="strState" />

    <asp:BoundField DataField="strContactName" HeaderText="Contact Name"
    SortExpression="strContactName" />

    <asp:BoundField DataField="strContactTitle" HeaderText="Contact Title"
    SortExpression="strContactTitle" />

    <asp:BoundField DataField="strContactPhone" HeaderText="Contact Phone"
    SortExpression="strContactPhone" />

    <asp:BoundField DataField="strContactEmail" HeaderText="Contact Email"
    SortExpression="strContactEmail" />

    <asp:TemplateField HeaderText="strNotes" SortExpression="strNotes">

    <EditItemTemplate>

    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("strNotes") %>'
    Columns="60" Rows="5" TextMode="MultiLine"></asp:TextBox>

    </EditItemTemplate>

    <InsertItemTemplate>

    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("strNotes") %>'
    Columns="60" Rows="5" TextMode="MultiLine"></asp:TextBox>

    </InsertItemTemplate>

    <ItemTemplate>

    <asp:Label ID="Label2" runat="server" Text='<%# Bind("strNotes")
    %>'></asp:Label>

    </ItemTemplate>

    </asp:TemplateField>

    <asp:BoundField DataField="dtModified" HeaderText="Modified" ReadOnly="True"
    SortExpression="dtModified" />

    <asp:CommandField ShowEditButton="True" ShowInsertButton="True" />

    </Fields>

    </asp:DetailsView>

    <br />

    <asp:Button ID="btnUpdate" runat="server" Text="Update" />

    &nbsp;&nbsp;

    <asp:Button ID="btnCancel" runat="server" Text="Cancel" />

    &nbsp;&nbsp;

    <asp:Button ID="btnDone" runat="server" Text="Done" Visible="False" />

    &nbsp; &nbsp;

    <asp:Label ID="lblStatus" runat="server" CssClass="required"></asp:Label><br
    />

    <br />

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

    SelectCommand="SELECT * FROM [tblEvents] WHERE ([ID] = @ID)"

    DeleteCommand="DELETE FROM [tblEvents] WHERE [ID] = @ID"

    InsertCommand="INSERT INTO [tblEvents] ([strTitle], [strDescription],
    [dtDate], [strSpeaker], [strHost], [strLocation], [strAddress], [strCity],
    [strState], [strContactName], [strContactTitle], [strContactPhone],
    [strContactEmail], [strNotes], [dtAdded], [dtModified]) VALUES (@strTitle,
    @strDescription, @dtDate, @strSpeaker, @strHost, @strLocation, @strAddress,
    @strCity, @strState, @strContactName, @strContactTitle, @strContactPhone,
    @strContactEmail, @strNotes, {fn Now()}, {fn Now()})"

    UpdateCommand="UPDATE [tblEvents] SET [strTitle] = @strTitle,
    [strDescription] = @strDescription, [dtDate] = @dtDate, [strSpeaker] =
    @strSpeaker, [strHost] = @strHost, [strLocation] = @strLocation,
    [strAddress] = @strAddress, [strCity] = @strCity, [strState] = @strState,
    [strContactName] = @strContactName, [strContactTitle] = @strContactTitle,
    [strContactPhone] = @strContactPhone, [strContactEmail] = @strContactEmail,
    [strNotes] = @strNotes, [dtModified] = {fn Now()} WHERE [ID] = @ID">

    <SelectParameters>

    <asp:QueryStringParameter Name="ID" QueryStringField="EID" Type="Int32" />

    </SelectParameters>

    <DeleteParameters>

    <asp:parameter Name="ID" Type="Int32" />

    </DeleteParameters>

    <UpdateParameters>

    <asp:parameter Name="strTitle" Type="String" />

    <asp:ControlParameter ControlID="dvDetails$TextBox1" PropertyName="Text"
    Name="strDescription" Type="string" />

    <asp:parameter Name="dtDate" Type="DateTime" />

    <asp:parameter Name="strSpeaker" Type="String" />

    <asp:parameter Name="strHost" Type="String" />

    <asp:parameter Name="strLocation" Type="String" />

    <asp:parameter Name="strAddress" Type="String" />

    <asp:parameter Name="strCity" Type="String" />

    <asp:parameter Name="strState" Type="String" />

    <asp:parameter Name="strContactName" Type="String" />

    <asp:parameter Name="strContactTitle" Type="String" />

    <asp:parameter Name="strContactPhone" Type="String" />

    <asp:parameter Name="strContactEmail" Type="String" />

    <asp:ControlParameter ControlID="dvDetails$TextBox2" PropertyName="Text"
    Name="strNotes" Type="string" />

    <asp:parameter Name="ID" Type="Int32" />

    </UpdateParameters>

    <InsertParameters>

    <asp:parameter Name="strTitle" Type="String" />

    <asp:parameter Name="strDescription" Type="String" />

    <asp:parameter Name="dtDate" Type="DateTime" />

    <asp:parameter Name="strSpeaker" Type="String" />

    <asp:parameter Name="strHost" Type="String" />

    <asp:parameter Name="strLocation" Type="String" />

    <asp:parameter Name="strAddress" Type="String" />

    <asp:parameter Name="strCity" Type="String" />

    <asp:parameter Name="strState" Type="String" />

    <asp:parameter Name="strContactName" Type="String" />

    <asp:parameter Name="strContactTitle" Type="String" />

    <asp:parameter Name="strContactPhone" Type="String" />

    <asp:parameter Name="strContactEmail" Type="String" />

    <asp:parameter Name="strNotes" Type="String" />

    </InsertParameters>

    </asp:SqlDataSource>





    Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles btnUpdate.Click

    dvDetails.UpdateItem(False)

    btnDone.Visible = True

    lblStatus.Text = "Event was updated successfully."

    End Sub
    David Lozzi, Jan 5, 2007
    #1
    1. Advertising

  2. David Lozzi

    David Lozzi Guest

    I went ahead and deleted the detailsview and the sqldatasource and recreated
    and it works great now...



    "David Lozzi" <> wrote in message
    news:%...
    > Howdy,
    >
    > I have a DetailsView that when I fire the UpdateItem event, it doesn't
    > update the data. The page reloads and the data is set back to the
    > original. I'm using a Button to fire the UpdateItem event and then leaves
    > the user a status stating that the event is updated, which does occur so i
    > know the button is firing properly. I haven't tried InsertItem yet, going
    > to set that up now. Any ideas why this is happening? My code is below.
    >
    > Thanks
    > David Lozzi
    >
    > <asp:DetailsView ID="dvDetails" runat="server" AutoGenerateRows="False"
    > DataSourceID="SqlDataSource1" BorderWidth="0px" DefaultMode="Edit">
    >
    > <Fields>
    >
    > <asp:BoundField DataField="strTitle" HeaderText="Title"
    > SortExpression="strTitle" />
    >
    > <asp:TemplateField HeaderText="strDescription"
    > SortExpression="strDescription">
    >
    > <EditItemTemplate>
    >
    > <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("strDescription")
    > %>' Columns="60" Rows="3" TextMode="MultiLine"></asp:TextBox>
    >
    > </EditItemTemplate>
    >
    > <InsertItemTemplate>
    >
    > <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("strDescription")
    > %>' Columns="60" Rows="3" TextMode="MultiLine"></asp:TextBox>
    >
    > </InsertItemTemplate>
    >
    > <ItemTemplate>
    >
    > <asp:Label ID="Label1" runat="server" Text='<%# Bind("strDescription")
    > %>'></asp:Label>
    >
    > </ItemTemplate>
    >
    > </asp:TemplateField>
    >
    > <asp:BoundField DataField="dtDate" HeaderText="Date"
    > SortExpression="dtDate" />
    >
    > <asp:BoundField DataField="strSpeaker" HeaderText="Speaker"
    > SortExpression="strSpeaker" />
    >
    > <asp:BoundField DataField="strHost" HeaderText="Host"
    > SortExpression="strHost" />
    >
    > <asp:BoundField DataField="strLocation" HeaderText="Location"
    > SortExpression="strLocation" />
    >
    > <asp:BoundField DataField="strAddress" HeaderText="Address"
    > SortExpression="strAddress" />
    >
    > <asp:BoundField DataField="strCity" HeaderText="City"
    > SortExpression="strCity" />
    >
    > <asp:BoundField DataField="strState" HeaderText="State"
    > SortExpression="strState" />
    >
    > <asp:BoundField DataField="strContactName" HeaderText="Contact Name"
    > SortExpression="strContactName" />
    >
    > <asp:BoundField DataField="strContactTitle" HeaderText="Contact Title"
    > SortExpression="strContactTitle" />
    >
    > <asp:BoundField DataField="strContactPhone" HeaderText="Contact Phone"
    > SortExpression="strContactPhone" />
    >
    > <asp:BoundField DataField="strContactEmail" HeaderText="Contact Email"
    > SortExpression="strContactEmail" />
    >
    > <asp:TemplateField HeaderText="strNotes" SortExpression="strNotes">
    >
    > <EditItemTemplate>
    >
    > <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("strNotes") %>'
    > Columns="60" Rows="5" TextMode="MultiLine"></asp:TextBox>
    >
    > </EditItemTemplate>
    >
    > <InsertItemTemplate>
    >
    > <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("strNotes") %>'
    > Columns="60" Rows="5" TextMode="MultiLine"></asp:TextBox>
    >
    > </InsertItemTemplate>
    >
    > <ItemTemplate>
    >
    > <asp:Label ID="Label2" runat="server" Text='<%# Bind("strNotes")
    > %>'></asp:Label>
    >
    > </ItemTemplate>
    >
    > </asp:TemplateField>
    >
    > <asp:BoundField DataField="dtModified" HeaderText="Modified"
    > ReadOnly="True" SortExpression="dtModified" />
    >
    > <asp:CommandField ShowEditButton="True" ShowInsertButton="True" />
    >
    > </Fields>
    >
    > </asp:DetailsView>
    >
    > <br />
    >
    > <asp:Button ID="btnUpdate" runat="server" Text="Update" />
    >
    > &nbsp;&nbsp;
    >
    > <asp:Button ID="btnCancel" runat="server" Text="Cancel" />
    >
    > &nbsp;&nbsp;
    >
    > <asp:Button ID="btnDone" runat="server" Text="Done" Visible="False" />
    >
    > &nbsp; &nbsp;
    >
    > <asp:Label ID="lblStatus" runat="server"
    > CssClass="required"></asp:Label><br />
    >
    > <br />
    >
    > <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    > ConnectionString="<%$ ConnectionStrings:SMALLConnectionString %>"
    >
    > SelectCommand="SELECT * FROM [tblEvents] WHERE ([ID] = @ID)"
    >
    > DeleteCommand="DELETE FROM [tblEvents] WHERE [ID] = @ID"
    >
    > InsertCommand="INSERT INTO [tblEvents] ([strTitle], [strDescription],
    > [dtDate], [strSpeaker], [strHost], [strLocation], [strAddress], [strCity],
    > [strState], [strContactName], [strContactTitle], [strContactPhone],
    > [strContactEmail], [strNotes], [dtAdded], [dtModified]) VALUES (@strTitle,
    > @strDescription, @dtDate, @strSpeaker, @strHost, @strLocation,
    > @strAddress, @strCity, @strState, @strContactName, @strContactTitle,
    > @strContactPhone, @strContactEmail, @strNotes, {fn Now()}, {fn Now()})"
    >
    > UpdateCommand="UPDATE [tblEvents] SET [strTitle] = @strTitle,
    > [strDescription] = @strDescription, [dtDate] = @dtDate, [strSpeaker] =
    > @strSpeaker, [strHost] = @strHost, [strLocation] = @strLocation,
    > [strAddress] = @strAddress, [strCity] = @strCity, [strState] = @strState,
    > [strContactName] = @strContactName, [strContactTitle] = @strContactTitle,
    > [strContactPhone] = @strContactPhone, [strContactEmail] =
    > @strContactEmail, [strNotes] = @strNotes, [dtModified] = {fn Now()} WHERE
    > [ID] = @ID">
    >
    > <SelectParameters>
    >
    > <asp:QueryStringParameter Name="ID" QueryStringField="EID" Type="Int32" />
    >
    > </SelectParameters>
    >
    > <DeleteParameters>
    >
    > <asp:parameter Name="ID" Type="Int32" />
    >
    > </DeleteParameters>
    >
    > <UpdateParameters>
    >
    > <asp:parameter Name="strTitle" Type="String" />
    >
    > <asp:ControlParameter ControlID="dvDetails$TextBox1" PropertyName="Text"
    > Name="strDescription" Type="string" />
    >
    > <asp:parameter Name="dtDate" Type="DateTime" />
    >
    > <asp:parameter Name="strSpeaker" Type="String" />
    >
    > <asp:parameter Name="strHost" Type="String" />
    >
    > <asp:parameter Name="strLocation" Type="String" />
    >
    > <asp:parameter Name="strAddress" Type="String" />
    >
    > <asp:parameter Name="strCity" Type="String" />
    >
    > <asp:parameter Name="strState" Type="String" />
    >
    > <asp:parameter Name="strContactName" Type="String" />
    >
    > <asp:parameter Name="strContactTitle" Type="String" />
    >
    > <asp:parameter Name="strContactPhone" Type="String" />
    >
    > <asp:parameter Name="strContactEmail" Type="String" />
    >
    > <asp:ControlParameter ControlID="dvDetails$TextBox2" PropertyName="Text"
    > Name="strNotes" Type="string" />
    >
    > <asp:parameter Name="ID" Type="Int32" />
    >
    > </UpdateParameters>
    >
    > <InsertParameters>
    >
    > <asp:parameter Name="strTitle" Type="String" />
    >
    > <asp:parameter Name="strDescription" Type="String" />
    >
    > <asp:parameter Name="dtDate" Type="DateTime" />
    >
    > <asp:parameter Name="strSpeaker" Type="String" />
    >
    > <asp:parameter Name="strHost" Type="String" />
    >
    > <asp:parameter Name="strLocation" Type="String" />
    >
    > <asp:parameter Name="strAddress" Type="String" />
    >
    > <asp:parameter Name="strCity" Type="String" />
    >
    > <asp:parameter Name="strState" Type="String" />
    >
    > <asp:parameter Name="strContactName" Type="String" />
    >
    > <asp:parameter Name="strContactTitle" Type="String" />
    >
    > <asp:parameter Name="strContactPhone" Type="String" />
    >
    > <asp:parameter Name="strContactEmail" Type="String" />
    >
    > <asp:parameter Name="strNotes" Type="String" />
    >
    > </InsertParameters>
    >
    > </asp:SqlDataSource>
    >
    >
    >
    >
    >
    > Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles btnUpdate.Click
    >
    > dvDetails.UpdateItem(False)
    >
    > btnDone.Visible = True
    >
    > lblStatus.Text = "Event was updated successfully."
    >
    > End Sub
    >
    >
    David Lozzi, Jan 9, 2007
    #2
    1. Advertising

  3. David Lozzi

    Mark Rae Guest

    "David Lozzi" <> wrote in message
    news:...

    > went ahead and


    :)
    Mark Rae, Jan 9, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roger
    Replies:
    1
    Views:
    463
    joeka
    Nov 17, 2005
  2. Replies:
    3
    Views:
    4,502
  3. ashishbuddha

    updating in detailsview

    ashishbuddha, Jul 18, 2006, in forum: .NET
    Replies:
    0
    Views:
    2,262
    ashishbuddha
    Jul 18, 2006
  4. John

    Detailsview not updating

    John, Jun 22, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    572
  5. Feege
    Replies:
    0
    Views:
    444
    Feege
    Dec 20, 2005
Loading...

Share This Page