DetailsView not updating


D

David Lozzi

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
 
Ad

Advertisements

D

David Lozzi

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



David Lozzi said:
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
 
Ad

Advertisements


Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top