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
<aspetailsView 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>
</aspetailsView>
<br />
<asp:Button ID="btnUpdate" runat="server" Text="Update" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
<asp:Button ID="btnDone" runat="server" Text="Done" Visible="False" />
<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>
<asparameter Name="ID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asparameter Name="strTitle" Type="String" />
<asp:ControlParameter ControlID="dvDetails$TextBox1" PropertyName="Text"
Name="strDescription" Type="string" />
<asparameter Name="dtDate" Type="DateTime" />
<asparameter Name="strSpeaker" Type="String" />
<asparameter Name="strHost" Type="String" />
<asparameter Name="strLocation" Type="String" />
<asparameter Name="strAddress" Type="String" />
<asparameter Name="strCity" Type="String" />
<asparameter Name="strState" Type="String" />
<asparameter Name="strContactName" Type="String" />
<asparameter Name="strContactTitle" Type="String" />
<asparameter Name="strContactPhone" Type="String" />
<asparameter Name="strContactEmail" Type="String" />
<asp:ControlParameter ControlID="dvDetails$TextBox2" PropertyName="Text"
Name="strNotes" Type="string" />
<asparameter Name="ID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asparameter Name="strTitle" Type="String" />
<asparameter Name="strDescription" Type="String" />
<asparameter Name="dtDate" Type="DateTime" />
<asparameter Name="strSpeaker" Type="String" />
<asparameter Name="strHost" Type="String" />
<asparameter Name="strLocation" Type="String" />
<asparameter Name="strAddress" Type="String" />
<asparameter Name="strCity" Type="String" />
<asparameter Name="strState" Type="String" />
<asparameter Name="strContactName" Type="String" />
<asparameter Name="strContactTitle" Type="String" />
<asparameter Name="strContactPhone" Type="String" />
<asparameter Name="strContactEmail" Type="String" />
<asparameter 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
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
<aspetailsView 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>
</aspetailsView>
<br />
<asp:Button ID="btnUpdate" runat="server" Text="Update" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
<asp:Button ID="btnDone" runat="server" Text="Done" Visible="False" />
<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>
<asparameter Name="ID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asparameter Name="strTitle" Type="String" />
<asp:ControlParameter ControlID="dvDetails$TextBox1" PropertyName="Text"
Name="strDescription" Type="string" />
<asparameter Name="dtDate" Type="DateTime" />
<asparameter Name="strSpeaker" Type="String" />
<asparameter Name="strHost" Type="String" />
<asparameter Name="strLocation" Type="String" />
<asparameter Name="strAddress" Type="String" />
<asparameter Name="strCity" Type="String" />
<asparameter Name="strState" Type="String" />
<asparameter Name="strContactName" Type="String" />
<asparameter Name="strContactTitle" Type="String" />
<asparameter Name="strContactPhone" Type="String" />
<asparameter Name="strContactEmail" Type="String" />
<asp:ControlParameter ControlID="dvDetails$TextBox2" PropertyName="Text"
Name="strNotes" Type="string" />
<asparameter Name="ID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asparameter Name="strTitle" Type="String" />
<asparameter Name="strDescription" Type="String" />
<asparameter Name="dtDate" Type="DateTime" />
<asparameter Name="strSpeaker" Type="String" />
<asparameter Name="strHost" Type="String" />
<asparameter Name="strLocation" Type="String" />
<asparameter Name="strAddress" Type="String" />
<asparameter Name="strCity" Type="String" />
<asparameter Name="strState" Type="String" />
<asparameter Name="strContactName" Type="String" />
<asparameter Name="strContactTitle" Type="String" />
<asparameter Name="strContactPhone" Type="String" />
<asparameter Name="strContactEmail" Type="String" />
<asparameter 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