<asp:SqlDataSource ID="SqlDSProspectEdit" runat="server"
ConnectionString="<%$ ConnectionStrings:PSI_DB_1ConnectionString %>"
SelectCommand="SELECT * FROM prospects where id=@id"
UpdateCommand="UPDATE prospects SET salespn =@salespn, class =@class, updated =GetDate(),
company =@company, contact =@contact, title =@title, street =@street, city =@city, state =@state,
zip =@zip, phone =@phone, mobile =@mobile, fax =@fax, email =@email, notes =@notes Where id=@id" >
<asp:SqlDataSource ID="SqlDSSalesReps" runat="server"
ConnectionString="<%$ ConnectionStrings:PSI_DB_1ConnectionString %>"
SelectCommand="SELECT DISTINCT salespn FROM prospects WHERE (salespn <> '') ORDER BY salespn" >
</asp:SqlDataSource>
Ruthless23
Member
157 Points
231 Posts
Detailsview won't update
Jul 13, 2010 08:54 PM|LINK
I have a detailsview that I used to add a record and copied into a page to edit records;
I think I changed all the code correctly but must have missed something I just can find
When I click update the screen the items are not updated. I can't find what I missed.
could really use anotyher set of eyes on this
aspx. file
<asp:DetailsView ID="dvEditProspect" runat="server" AutoGenerateRows="False"
BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
CellPadding="3" CellSpacing="2" DataSourceID="SqlDSProspectEdit"
OnItemUpdated ="dvEditProspect_ItemUpdated"
OnItemCommand="dvEditProspect_ItemCommand"
OnItemUpdating="dvEditProspect_ItemUpdating"
DefaultMode="Edit" Height="70px" Width="350px" CssClass="GridViews"
HeaderText="Edit Prospect">
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<Fields>
<asp:TemplateField ConvertEmptyStringToNull="False" HeaderText="Sales Rep" SortExpression="salespn">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("salespn") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlSalesRep" runat="server" CssClass="GridViews"
DataSourceID="SqlDSSalesReps" DataTextField="salespn"
DataValueField="salespn" SelectedValue='<%# Bind("salespn") %>'>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvSalesRep" runat="server" Display="Dynamic"
ErrorMessage="Sales Rep is required" ControlToValidate="ddlSalesRep"></asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField
HeaderText="Class" SortExpression="class" ConvertEmptyStringToNull="False">
<EditItemTemplate>
<asp:DropDownList
runat="server"
ID="ddlClass"
CssClass="GridViews"
Text='<%# Bind("class") %>'>
<asp:ListItem Value="D">D - Dormant</asp:ListItem>
<asp:ListItem Value="C">C - Cool Prospect</asp:ListItem>
<asp:ListItem Value="B">B - Burning Hot Prospect</asp:ListItem>
<asp:ListItem Value="A">A - Active in PSI</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvClass" runat="server" Display="Dynamic"
ErrorMessage="Class is required" ControlToValidate="ddlClass"></asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Company" SortExpression="company" ConvertEmptyStringToNull="False">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("company") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtbxCompany" runat="server" Text='<%# Bind("company") %>' Columns="60" CssClass="GridViews" MaxLength="60"></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="rfvCompany" runat="server" Display="Dynamic"
ErrorMessage="Company is required" ControlToValidate="txtbxCompany"></asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Contact" SortExpression="contact" ConvertEmptyStringToNull="False">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("contact") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtbxContact" Columns="60" CssClass="GridViews" MaxLength="60" runat="server" Text='<%# Bind("contact") %>'></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="rfvContact" runat="server" Display="Dynamic"
ErrorMessage="Contact is required" ControlToValidate="txtbxcontact"></asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Title" SortExpression="title" ConvertEmptyStringToNull="False">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("title") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtBxTitle" Columns="60" CssClass="GridViews" MaxLength="60" runat="server" Text='<%# Bind("title") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Street" SortExpression="street" ConvertEmptyStringToNull="False">
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("street") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtBxStreet" Columns="60" CssClass="GridViews" MaxLength="60" runat="server" Text='<%# Bind("street") %>'></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="rfvStreet" runat="server" Display="Dynamic"
ErrorMessage="Street is required" ControlToValidate="txtbxStreet"></asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="City" SortExpression="city" ConvertEmptyStringToNull="False">
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("city") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtBxCity" Columns="40" CssClass="GridViews" MaxLength="40" runat="server" Text='<%# Bind("city") %>'></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="rfvCity" runat="server" Display="Dynamic"
ErrorMessage="City is required" ControlToValidate="txtbxcity"></asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="State" SortExpression="state" ConvertEmptyStringToNull="False">
<ItemTemplate>
<asp:Label ID="lblState" runat="server" Text='<%# Bind("state") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList runat="server" ID="ddlState" CssClass="GridViews" Text='<%# Bind("state") %>'>
<asp:ListItem Value="CA"></asp:ListItem>
<asp:ListItem Value="AL"></asp:ListItem>
<asp:ListItem Value="AK"></asp:ListItem>
<asp:ListItem Value="AS"></asp:ListItem>
<asp:ListItem Value="AZ"></asp:ListItem>
<asp:ListItem Value="AR"></asp:ListItem>
<asp:ListItem Value="CN"></asp:ListItem>
<asp:ListItem Value="CO"></asp:ListItem>
<asp:ListItem Value="CT"></asp:ListItem>
<asp:ListItem Value="CN"></asp:ListItem>
<asp:ListItem Value="DE"></asp:ListItem>
<asp:ListItem Value="DC"></asp:ListItem>
<asp:ListItem Value="FL"></asp:ListItem>
<asp:ListItem Value="GA"></asp:ListItem>
<asp:ListItem Value="HI"></asp:ListItem>
<asp:ListItem Value="ID"></asp:ListItem>
<asp:ListItem Value="IL"></asp:ListItem>
<asp:ListItem Value="IN"></asp:ListItem>
<asp:ListItem Value="IA"></asp:ListItem>
<asp:ListItem Value="KS"></asp:ListItem>
<asp:ListItem Value="KY"></asp:ListItem>
<asp:ListItem Value="LA"></asp:ListItem>
<asp:ListItem Value="ME"></asp:ListItem>
<asp:ListItem Value="MH"></asp:ListItem>
<asp:ListItem Value="MD"></asp:ListItem>
<asp:ListItem Value="MA"></asp:ListItem>
<asp:ListItem Value="MI"></asp:ListItem>
<asp:ListItem Value="MN"></asp:ListItem>
<asp:ListItem Value="MS"></asp:ListItem>
<asp:ListItem Value="MO"></asp:ListItem>
<asp:ListItem Value="MT"></asp:ListItem>
<asp:ListItem Value="MX"></asp:ListItem>
<asp:ListItem Value="NE"></asp:ListItem>
<asp:ListItem Value="NV"></asp:ListItem>
<asp:ListItem Value="NH"></asp:ListItem>
<asp:ListItem Value="NJ"></asp:ListItem>
<asp:ListItem Value="NM"></asp:ListItem>
<asp:ListItem Value="NY"></asp:ListItem>
<asp:ListItem Value="NC"></asp:ListItem>
<asp:ListItem Value="ND"></asp:ListItem>
<asp:ListItem Value="OH"></asp:ListItem>
<asp:ListItem Value="OK"></asp:ListItem>
<asp:ListItem Value="OR"></asp:ListItem>
<asp:ListItem Value="PW"></asp:ListItem>
<asp:ListItem Value="PA"></asp:ListItem>
<asp:ListItem Value="RI"></asp:ListItem>
<asp:ListItem Value="SC"></asp:ListItem>
<asp:ListItem Value="SD"></asp:ListItem>
<asp:ListItem Value="TN"></asp:ListItem>
<asp:ListItem Value="TX"></asp:ListItem>
<asp:ListItem Value="UT"></asp:ListItem>
<asp:ListItem Value="VT"></asp:ListItem>
<asp:ListItem Value="VI"></asp:ListItem>
<asp:ListItem Value="VA"></asp:ListItem>
<asp:ListItem Value="WA"></asp:ListItem>
<asp:ListItem Value="WV"></asp:ListItem>
<asp:ListItem Value="WI"></asp:ListItem>
<asp:ListItem Value="WY"></asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvState" runat="server" Display="Dynamic"
ErrorMessage="State is required" ControlToValidate="ddlState"></asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Zip" SortExpression="zip" ConvertEmptyStringToNull="False">
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Bind("zip") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtBxZip" Columns="10" CssClass="GridViews" MaxLength="10" runat="server" Text='<%# Bind("zip") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvZip" runat="server" Display="Dynamic"
ErrorMessage="Zip Code is required" ControlToValidate="txtbxzip"></asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Phone" SortExpression="phone" ConvertEmptyStringToNull="False">
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%# Bind("phone") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtBxPhone" Columns="30" CssClass="GridViews" MaxLength="30" runat="server" Text='<%# Bind("phone") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Mobile" SortExpression="mobile" ConvertEmptyStringToNull="False">
<ItemTemplate>
<asp:Label ID="Label10" runat="server" Text='<%# Bind("mobile") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtBxMobile" Columns="30" CssClass="GridViews" MaxLength="30" runat="server" Text='<%# Bind("mobile") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Fax" SortExpression="fax" ConvertEmptyStringToNull="False">
<ItemTemplate>
<asp:Label ID="Label11" runat="server" Text='<%# Bind("fax") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtBxFax" Columns="30" CssClass="GridViews" MaxLength="30" runat="server" Text='<%# Bind("fax") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Email" SortExpression="email" ConvertEmptyStringToNull="False">
<ItemTemplate>
<asp:Label ID="Label12" runat="server" Text='<%# Bind("email") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtBxEmail" Columns="50" CssClass="GridViews" MaxLength="50" runat="server" Text='<%# Bind("email") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Notes" SortExpression="notes" ConvertEmptyStringToNull="False">
<ItemTemplate>
<asp:Label ID="Label13" runat="server" Text='<%# Bind("notes") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtBxNotes" CssClass="GridViews" runat="server"
Text='<%# Bind("notes") %>' Height="100px" TextMode="MultiLine" Width="280px"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Fields>
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#DEBA84" BorderColor="#DEBA84" Font-Bold="True" />
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDSProspectEdit" runat="server"
ConnectionString="<%$ ConnectionStrings:PSI_DB_1ConnectionString %>"
SelectCommand="SELECT * FROM prospects where id=@id"
UpdateCommand="UPDATE prospects SET salespn =@salespn, class =@class, updated =GetDate(),
company =@company, contact =@contact, title =@title, street =@street, city =@city, state =@state,
zip =@zip, phone =@phone, mobile =@mobile, fax =@fax, email =@email, notes =@notes Where id=@id" >
<SelectParameters>
<asp:QueryStringParameter Name="id" QueryStringField="id" Type="Int32"/>
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="salespn" DefaultValue=" " />
<asp:Parameter Name="class" DefaultValue=" " />
<asp:Parameter Name="company" DefaultValue=" " />
<asp:Parameter Name="contact" DefaultValue=" " />
<asp:Parameter Name="title" DefaultValue=" " />
<asp:Parameter Name="street" DefaultValue=" " />
<asp:Parameter Name="city" DefaultValue=" " />
<asp:Parameter Name="state" DefaultValue=" " />
<asp:Parameter Name="zip" DefaultValue=" " />
<asp:Parameter Name="phone" DefaultValue=" " />
<asp:Parameter Name="mobile" DefaultValue=" " />
<asp:Parameter Name="fax" DefaultValue=" " />
<asp:Parameter Name="email" DefaultValue=" " />
<asp:Parameter Name="notes" DefaultValue=" " />
<asp:Parameter Name="id" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDSSalesReps" runat="server"
ConnectionString="<%$ ConnectionStrings:PSI_DB_1ConnectionString %>"
SelectCommand="SELECT DISTINCT salespn FROM prospects WHERE (salespn <> '') ORDER BY salespn" >
</asp:SqlDataSource>
Code behind file
protected void dvEditProspect_ItemCommand(object sender, DetailsViewCommandEventArgs e)
{
String theLetter = Request.QueryString["letterChoice"];
if (e.CommandName == "Cancel")
{
Response.Redirect("~/ProspectsShow.aspx");
}
}
public void dvEditProspect_ItemUpdating(object sender, System.Web.UI.WebControls.DetailsViewUpdateEventArgs e)
{
foreach (System.Collections.DictionaryEntry entry in e.NewValues)
{
e.NewValues[entry.Key] = System.Web.HttpUtility.HtmlEncode(entry.Value.ToString());
}
}
public void dvEditProspect_ItemUpdated(object sender, System.Web.UI.WebControls.DetailsViewUpdatedEventArgs e)
{
Response.Redirect("~/ProspectsShow.aspx");
}
PeteNet
All-Star
81342 Points
11398 Posts
Re: Detailsview won't update
Jul 13, 2010 09:33 PM|LINK
I didn't finish reading through, but you could use DataKeyNames="ID" on the D (is it ID?) DetailsView
Peter
Hisham.NET
Participant
1794 Points
460 Posts
Re: Detailsview won't update
Jul 13, 2010 09:41 PM|LINK
Hi Ruthless23 ...
Ya of course you miss DataKeyNames="ID" without it no updation 'll made in your database.
Good Luck
Ruthless23
Member
157 Points
231 Posts
Re: Detailsview won't update
Jul 13, 2010 09:48 PM|LINK
that was it thanks
Makes sense it would not be in the add but needed in the edit
thanks again