locked
Edit a record in ASP.NET C# Won't update. RRS feed

  • Question

  • User1215529056 posted

    I had code running on a Windows XP intranet server. Moved it to Windows 7 Pro and VS 2015.

    Linked to the same SQL server but now updates fail from the web page where they worked before.

    Page Code --------------------------------------------

    <%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" ValidateRequest="false" CodeFile="VendorEdit.aspx.cs" Inherits="VendorEdit" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <asp:DetailsView ID="dvEditVendor" runat="server" AutoGenerateRows="False"
    BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
    CellPadding="3" CellSpacing="2"
    DataKeyNames="idnum"
    DataSourceID="SqDSVendor"
    OnItemUpdating="dvEditVendor_ItemUpdating"
    OnItemUpdated="dvEditVendor_ItemUpdated"
    OnItemCommand="dvEditVendor_ItemCommand"


    Height="50px" Width="125px" CssClass="GridViews" DefaultMode="Edit">
    <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
    <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
    <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
    <Fields>
    <asp:TemplateField HeaderText="Expertise" SortExpression="expertise"
    ItemStyle-CssClass="GridViews" ConvertEmptyStringToNull="False" >
    <ItemTemplate>
    <asp:Label ID="lblExpertise" runat="server" Text='<%# Bind("expertise") %>'></asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="txtbxExpertise" runat="server" Columns="40" CssClass="GridViews" Text='<%# Bind("expertise") %>' MaxLength="40"></asp:TextBox>
    <br />
    <asp:RequiredFieldValidator ID="rfvExpertise" runat="server" Display="Dynamic"
    ErrorMessage="Expertise is Required" ControlToValidate="txtbxExpertise"></asp:RequiredFieldValidator>
    </EditItemTemplate>
    <InsertItemTemplate>
    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("expertise") %>'></asp:TextBox>
    </InsertItemTemplate>
    <HeaderStyle Wrap="False" />

    <ItemStyle CssClass="GridViews"></ItemStyle>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Company" SortExpression="company"
    ItemStyle-CssClass="GridViews" ConvertEmptyStringToNull="False">
    <ItemTemplate>
    <asp:Label ID="Label2" runat="server" Text='<%# Bind("company") %>'></asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="txtbxCompany" runat="server" Columns="50" CssClass="GridViews" Text='<%# Bind("company") %>' MaxLength="50"></asp:TextBox>
    <br />
    <asp:RequiredFieldValidator ID="rfvCompany" runat="server" Display="Dynamic"
    ErrorMessage="Company is Required" ControlToValidate="txtbxCompany"></asp:RequiredFieldValidator>
    </EditItemTemplate>
    <InsertItemTemplate>
    <asp:TextBox ID="txtbxCompany" runat="server" Text='<%# Bind("company") %>'></asp:TextBox>
    </InsertItemTemplate>

    <ItemStyle CssClass="GridViews"></ItemStyle>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Contact" SortExpression="contact"
    ItemStyle-CssClass="GridViews" ConvertEmptyStringToNull="False">
    <ItemTemplate>
    <asp:Label ID="Label3" runat="server" Text='<%# Bind("contact") %>'></asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="txtBxContact" runat="server" Columns="40" CssClass="GridViews" Text='<%# Bind("contact") %>' MaxLength="40"></asp:TextBox>
    </EditItemTemplate>
    <InsertItemTemplate>
    <asp:TextBox ID="txtBxContact" runat="server" Text='<%# Bind("contact") %>'></asp:TextBox>
    </InsertItemTemplate>

    <ItemStyle CssClass="GridViews"></ItemStyle>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Phone" SortExpression="phone"
    ItemStyle-CssClass="GridViews" ConvertEmptyStringToNull="False">
    <ItemTemplate>
    <asp:Label ID="Label4" runat="server" Text='<%# Bind("phone") %>'></asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="txtBxPhone" runat="server" Columns="25" CssClass="GridViews" Text='<%# Bind("phone") %>' MaxLength="25"></asp:TextBox>
    <br />
    <asp:RequiredFieldValidator ID="rfvPhone" runat="server" Display="Dynamic"
    ErrorMessage="Phone # is Required" ControlToValidate="txtBxPhone"></asp:RequiredFieldValidator>
    </EditItemTemplate>
    <InsertItemTemplate>
    <asp:TextBox ID="txtBxPhone" runat="server" Text='<%# Bind("phone") %>'></asp:TextBox>
    </InsertItemTemplate>

    <ItemStyle CssClass="GridViews"></ItemStyle>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Hours" SortExpression="hours"
    ItemStyle-CssClass="GridViews" ConvertEmptyStringToNull="False">
    <ItemTemplate>
    <asp:Label ID="Label5" runat="server" Text='<%# Bind("hours") %>'></asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="TextBox5" runat="server" Columns="20" CssClass="GridViews" Text='<%# Bind("hours") %>' MaxLength="20"></asp:TextBox>
    </EditItemTemplate>
    <InsertItemTemplate>
    <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("hours") %>'></asp:TextBox>
    </InsertItemTemplate>

    <ItemStyle CssClass="GridViews"></ItemStyle>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Contact" SortExpression="contact2"
    ItemStyle-CssClass="GridViews" ConvertEmptyStringToNull="False">
    <ItemTemplate>
    <asp:Label ID="Label6" runat="server" Text='<%# Bind("contact2") %>'></asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="TextBox6" runat="server" Columns="40" CssClass="GridViews" Text='<%# Bind("contact2") %>' MaxLength="40"></asp:TextBox>
    </EditItemTemplate>
    <InsertItemTemplate>
    <asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("contact2") %>'></asp:TextBox>
    </InsertItemTemplate>

    <ItemStyle CssClass="GridViews"></ItemStyle>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Cell #" SortExpression="cell"
    ItemStyle-CssClass="GridViews" ConvertEmptyStringToNull="False">
    <ItemTemplate>
    <asp:Label ID="Label7" runat="server" Text='<%# Bind("cell") %>'></asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="TextBox7" runat="server" Columns="25" CssClass="GridViews" Text='<%# Bind("cell") %>' MaxLength="25"></asp:TextBox>
    </EditItemTemplate>
    <InsertItemTemplate>
    <asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("cell") %>'></asp:TextBox>
    </InsertItemTemplate>

    <ItemStyle CssClass="GridViews"></ItemStyle>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Hours" SortExpression="hours2"
    ItemStyle-CssClass="GridViews" ConvertEmptyStringToNull="False">
    <ItemTemplate>
    <asp:Label ID="Label8" runat="server" Text='<%# Bind("hours2") %>'></asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="TextBox8" runat="server" Columns="20" CssClass="GridViews" Text='<%# Bind("hours2") %>' MaxLength="20"></asp:TextBox>
    </EditItemTemplate>
    <InsertItemTemplate>
    <asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("hours2") %>'></asp:TextBox>
    </InsertItemTemplate>

    <ItemStyle CssClass="GridViews"></ItemStyle>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Notes" SortExpression="notes"
    ConvertEmptyStringToNull="False">
    <ItemTemplate>
    <asp:Label ID="Label9" runat="server" Text='<%# Bind("notes") %>'></asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="txtBxNotes" runat="server" Height="100px" Columns="50" CssClass="GridViews" Text='<%# Bind("notes") %>' TextMode="MultiLine"></asp:TextBox>
    </EditItemTemplate>
    <InsertItemTemplate>
    <asp:TextBox ID="txtBxNotes" runat="server" Text='<%# Bind("notes") %>'></asp:TextBox>
    </InsertItemTemplate>
    </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="SqDSVendor" runat="server"
    ConnectionString="<%$ ConnectionStrings:Enterprise32ConnectionString %>"
    SelectCommand="SELECT * FROM [VendorInfo9ish] WHERE ([idnum] = @idnum)"
    UpdateCommand="UPDATE VendorContact SET
    expertise = @expertise,
    company = @company,
    contact = @contact,
    phone = @phone,
    hours = @hours,
    contact2 = @contact2,
    cell = @cell,
    hours2 = @hours2,
    notes = @notes
    WHERE (idnum = @idnum)">

    <SelectParameters>
    <asp:QueryStringParameter Name="idnum" QueryStringField="idnum" Type="Int32" />
    </SelectParameters>

    <UpdateParameters>
    <asp:Parameter Name="expertise" Type="String" />
    <asp:Parameter Name="company" Type="String" />
    <asp:Parameter Name="contact" Type="String" />
    <asp:Parameter Name="phone" Type="String" />
    <asp:Parameter Name="hours" Type="String" />
    <asp:Parameter Name="contact2" Type="String" />
    <asp:Parameter Name="cell" Type="String" DefaultValue=" "/>
    <asp:Parameter Name="hours2" Type="String" DefaultValue=" "/>
    <asp:Parameter Name="notes" Type="String" DefaultValue=" "/>
    <asp:Parameter Name="idnum" Type="Int32" />
    </UpdateParameters>
    </asp:SqlDataSource>

    </asp:Content>

    Code Behind File

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public partial class VendorEdit : System.Web.UI.Page
    {


    public void dvEditVendor_ItemUpdating(Object sender, DetailsViewUpdateEventArgs e)
    {
    foreach (System.Collections.DictionaryEntry entry in e.NewValues)
    {
    e.NewValues[entry.Key] = System.Web.HttpUtility.HtmlEncode(entry.Value.ToString());
    }
    }

    public void dvEditVendor_ItemUpdated(Object sender, DetailsViewUpdatedEventArgs e)
    {
    Response.Redirect("~/VendorsShow.aspx");
    }

    protected void dvEditVendor_ItemCommand(object sender, DetailsViewCommandEventArgs e)
    {
    if (e.CommandName == "Cancel")
    {
    Response.Redirect("~/VendorsShow.aspx");

    // DetailsView1.Visible = false;
    // SitesView.Visible = true;
    // Button1.Visible = true;
    // DetailsView1.EnableViewState = false;
    // SitesView.DataBind();
    }
    }

    }

    Connection String----------------------------------------

    <connectionStrings>
    <add name="Enterprise32ConnectionString" connectionString="Data Source=10.0.0.18;Initial Catalog=Enterprise32;Persist Security Info=True;User ID=sa;Password=XXXXXXXXX" providerName="System.Data.SqlClient"/>
    </connectionStrings>

    Wednesday, May 8, 2019 9:00 PM

Answers

  • User753101303 posted

    Hi,

    In addition make sure exceptions are reported to someone so that the application doesn't fail silently. If I remember you can check what happened in variuous events (for example how many rows were updated, it might worth to check that if you assume you should always update exactly one row).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 9, 2019 9:09 AM

All replies

  • User475983607 posted

    What's the error?

    Wednesday, May 8, 2019 9:04 PM
  • User1215529056 posted

    no error. Just no update. It's as if the record id is missing so it can't find the record to update. I didn't change any code that should have effected this.

    Wednesday, May 8, 2019 9:55 PM
  • User288213138 posted

    Hi RuthlessRoth,
     

    I tried to reproduce your problem and found that the table you are querying is VendorInfo9ish, and the updated table is VendorContact, of course you won't see the updates on the page.

     You code:

    SelectCommand="SELECT * FROM [VendorInfo9ish] WHERE ([idnum] = @idnum)" 
    UpdateCommand="UPDATE VendorContact SET 
    expertise = @expertise, 
    company = @company, 
    contact = @contact, 
    phone = @phone, 
    hours = @hours, 
    contact2 = @contact2, 
    cell = @cell, 
    hours2 = @hours2, 
    notes = @notes 
    WHERE (idnum = @idnum)"

    Best Regard,
    Sam

    Thursday, May 9, 2019 8:51 AM
  • User753101303 posted

    Hi,

    In addition make sure exceptions are reported to someone so that the application doesn't fail silently. If I remember you can check what happened in variuous events (for example how many rows were updated, it might worth to check that if you assume you should always update exactly one row).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 9, 2019 9:09 AM
  • User1215529056 posted

    Good catch.

    I had to check the table name and server a long time ago and missed the update.

    Thanks

    Thursday, May 9, 2019 12:50 PM
  • User1215529056 posted

    new problem. The change worked once and I was able to make the edit now I'm getting this on the remote site.

    Collection was modified; enumeration operation may not execute.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.InvalidOperationException: Collection was modified; enumeration operation may not execute.

    Source Error:

    Line 12:     public void dvEditVendor_ItemUpdating(Object sender, DetailsViewUpdateEventArgs e)
    Line 13:     {
    Line 14:         foreach (System.Collections.DictionaryEntry entry in e.NewValues)
    Line 15:         {
    Line 16:             e.NewValues[entry.Key] = System.Web.HttpUtility.HtmlEncode(entry.Value.ToString());


    Source File: c:\inetpub\wwwroot\9ishNewInternal\VendorEdit.aspx.cs    Line: 14

    Thursday, May 9, 2019 6:44 PM
  • User288213138 posted

    Hi RuthlessRoth,

    You can use the IOrderedDictionary to get the data to be updated, then use the for loop to traverse the data.

     The code:

    public void dvEditVendor_ItemUpdating(Object sender, DetailsViewUpdateEventArgs e)
            {
                IOrderedDictionary dic = e.NewValues;
                
                for (int i = 0; i < dic.Keys.Count; i++)
                {
    
                    e.NewValues[i] = System.Web.HttpUtility.HtmlEncode(e.NewValues[i].ToString());
                   
                }          
            }
    

    The Result:

    Best Regards,

    Sam

    Monday, May 13, 2019 10:43 AM
  • User1215529056 posted

    Had to add

    using System.Collections.Specialized; to get the

    IOrderedDictionary

    Almost. No enumeration error.

    I have to put a value in the field I want to edit or it ignores the change.

    I can't leave a empty field where there was data in it before.

    Field ad this wrtwqertdfvg

    Deleted all characters and it left the wrtwqertdfvg in place.

    Monday, May 13, 2019 6:57 PM
  • User288213138 posted

    Hi RuthlessRoth,


     
    In your Aspx, there is a RequiredFieldValidator control that makes the associated input control a required field.

     

    So delete it and it will work fine.

    The result:

    Best regards,

    Sam

    Wednesday, May 15, 2019 6:59 AM
  • User1215529056 posted

    on the required that is true. My test field is contact2 and there is no required field.

    I put a lot of 8s as a test. it saves. remove all the 8s creating an empty field it does not update any fields.

    Example:

    added -1 to the first 3 fields and remove the 8's from contact2. No fields are updated

    added -1 to the first 3 fields and replace the 8s with a period '.' it updates

    Wednesday, May 15, 2019 4:03 PM
  • User288213138 posted

    Hi RuthlessRoth,
     
    I tried what you described, but my code works. And my test code is provided by you.

     Please check your database and code. If the problem has not been solved, please post your modified code.

     The code:

    Aspx:
    <asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
    
      <asp:DetailsView ID="dvEditVendor" runat="server" AutoGenerateRows="False"
            BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
            CellPadding="3" CellSpacing="2"
            DataKeyNames="idnum"
            DataSourceID="SqDSVendor"
            OnItemUpdating="dvEditVendor_ItemUpdating"
            OnItemUpdated="dvEditVendor_ItemUpdated"
            OnItemCommand="dvEditVendor_ItemCommand"
            Height="50px" Width="125px" CssClass="GridViews" DefaultMode="Edit">
            <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
            <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
            <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
            <Fields>
                <asp:TemplateField HeaderText="Expertise" SortExpression="expertise"
                    ItemStyle-CssClass="GridViews" ConvertEmptyStringToNull="False">
                    <ItemTemplate>
                        <asp:Label ID="lblExpertise" runat="server" Text='<%# Bind("expertise") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtbxExpertise" runat="server" Columns="40" CssClass="GridViews" Text='<%# Bind("expertise") %>' MaxLength="40"></asp:TextBox>
                        <br />
                       <%-- <asp:RequiredFieldValidator ID="rfvExpertise" runat="server" Display="Dynamic"
                            ErrorMessage="Expertise is Required" ControlToValidate="txtbxExpertise"></asp:RequiredFieldValidator>--%>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("expertise") %>'></asp:TextBox>
                    </InsertItemTemplate>
                    <HeaderStyle Wrap="False" />
    
                    <ItemStyle CssClass="GridViews"></ItemStyle>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Company" SortExpression="company"
                    ItemStyle-CssClass="GridViews" ConvertEmptyStringToNull="False">
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("company") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtbxCompany" runat="server" Columns="50" CssClass="GridViews" Text='<%# Bind("company") %>' MaxLength="50"></asp:TextBox>
                        <br />
                        <%--<asp:RequiredFieldValidator ID="rfvCompany" runat="server" Display="Dynamic"
                            ErrorMessage="Company is Required" ControlToValidate="txtbxCompany"></asp:RequiredFieldValidator>--%>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="txtbxCompany" runat="server" Text='<%# Bind("company") %>'></asp:TextBox>
                    </InsertItemTemplate>
    
                    <ItemStyle CssClass="GridViews"></ItemStyle>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Contact" SortExpression="contact"
                    ItemStyle-CssClass="GridViews" ConvertEmptyStringToNull="False">
                    <ItemTemplate>
                        <asp:Label ID="Label3" runat="server" Text='<%# Bind("contact") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtBxContact" runat="server" Columns="40" CssClass="GridViews" Text='<%# Bind("contact") %>' MaxLength="40"></asp:TextBox>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="txtBxContact" runat="server" Text='<%# Bind("contact") %>'></asp:TextBox>
                    </InsertItemTemplate>
    
                    <ItemStyle CssClass="GridViews"></ItemStyle>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Phone" SortExpression="phone"
                    ItemStyle-CssClass="GridViews" ConvertEmptyStringToNull="False">
                    <ItemTemplate>
                        <asp:Label ID="Label4" runat="server" Text='<%# Bind("phone") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtBxPhone" runat="server" Columns="25" CssClass="GridViews" Text='<%# Bind("phone") %>' MaxLength="25"></asp:TextBox>
                        <br />
                        <%--<asp:RequiredFieldValidator ID="rfvPhone" runat="server" Display="Dynamic"
                            ErrorMessage="Phone # is Required" ControlToValidate="txtBxPhone"></asp:RequiredFieldValidator>--%>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="txtBxPhone" runat="server" Text='<%# Bind("phone") %>'></asp:TextBox>
                    </InsertItemTemplate>
    
                    <ItemStyle CssClass="GridViews"></ItemStyle>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Hours" SortExpression="hours"
                    ItemStyle-CssClass="GridViews" ConvertEmptyStringToNull="False">
                    <ItemTemplate>
                        <asp:Label ID="Label5" runat="server" Text='<%# Bind("hours") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox5" runat="server" Columns="20" CssClass="GridViews" Text='<%# Bind("hours") %>' MaxLength="20"></asp:TextBox>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("hours") %>'></asp:TextBox>
                    </InsertItemTemplate>
    
                    <ItemStyle CssClass="GridViews"></ItemStyle>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Contact" SortExpression="contact2"
                    ItemStyle-CssClass="GridViews" ConvertEmptyStringToNull="False">
                    <ItemTemplate>
                        <asp:Label ID="Label6" runat="server" Text='<%# Bind("contact2") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox6" runat="server" Columns="40" CssClass="GridViews" Text='<%# Bind("contact2") %>' MaxLength="40"></asp:TextBox>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("contact2") %>'></asp:TextBox>
                    </InsertItemTemplate>
    
                    <ItemStyle CssClass="GridViews"></ItemStyle>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Cell #" SortExpression="cell"
                    ItemStyle-CssClass="GridViews" ConvertEmptyStringToNull="False">
                    <ItemTemplate>
                        <asp:Label ID="Label7" runat="server" Text='<%# Bind("cell") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox7" runat="server" Columns="25" CssClass="GridViews" Text='<%# Bind("cell") %>' MaxLength="25"></asp:TextBox>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("cell") %>'></asp:TextBox>
                    </InsertItemTemplate>
    
                    <ItemStyle CssClass="GridViews"></ItemStyle>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Hours" SortExpression="hours2"
                    ItemStyle-CssClass="GridViews" ConvertEmptyStringToNull="False">
                    <ItemTemplate>
                        <asp:Label ID="Label8" runat="server" Text='<%# Bind("hours2") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox8" runat="server" Columns="20" CssClass="GridViews" Text='<%# Bind("hours2") %>' MaxLength="20"></asp:TextBox>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("hours2") %>'></asp:TextBox>
                    </InsertItemTemplate>
    
                    <ItemStyle CssClass="GridViews"></ItemStyle>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Notes" SortExpression="notes"
                    ConvertEmptyStringToNull="False">
                    <ItemTemplate>
                        <asp:Label ID="Label9" runat="server" Text='<%# Bind("notes") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtBxNotes" runat="server" Height="100px" Columns="50" CssClass="GridViews" Text='<%# Bind("notes") %>' TextMode="MultiLine"></asp:TextBox>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="txtBxNotes" runat="server" Text='<%# Bind("notes") %>'></asp:TextBox>
                    </InsertItemTemplate>
                </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="SqDSVendor" runat="server" ConnectionString="<%$ ConnectionStrings:TestConnectionString %>" DeleteCommand="DELETE FROM [VendorContact] WHERE [idnum] = @idnum" InsertCommand="INSERT INTO [VendorContact] ([idnum], [expertise], [company], [contact], [phone], [hours], [contact2], [cell], [hours2], [notes]) VALUES (@idnum, @expertise, @company, @contact, @phone, @hours, @contact2, @cell, @hours2, @notes)" SelectCommand="SELECT * FROM [VendorContact] WHERE ([idnum] = @idnum)" UpdateCommand="UPDATE [VendorContact] SET [expertise] = @expertise, [company] = @company, [contact] = @contact, [phone] = @phone, [hours] = @hours, [contact2] = @contact2, [cell] = @cell, [hours2] = @hours2, [notes] = @notes WHERE [idnum] = @idnum">
            <DeleteParameters>
                <asp:Parameter Name="idnum" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="idnum" Type="Int32" />
                <asp:Parameter Name="expertise" Type="String" />
               <asp:Parameter Name="company" Type="String" />
                <asp:Parameter Name="contact" Type="String" />
                <asp:Parameter Name="phone" Type="String" />
                <asp:Parameter Name="hours" Type="String" />
                <asp:Parameter Name="contact2" Type="String" />
                <asp:Parameter Name="cell" Type="String" />
                <asp:Parameter Name="hours2" Type="String" />
                <asp:Parameter Name="notes" Type="String" />
            </InsertParameters>
            <SelectParameters>
                <asp:QueryStringParameter DefaultValue="1" Name="idnum" QueryStringField="idnum" Type="Int32" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="expertise" Type="String" />
               <asp:Parameter Name="company" Type="String" />
                <asp:Parameter Name="contact" Type="String" />
                <asp:Parameter Name="phone" Type="String" />
                <asp:Parameter Name="hours" Type="String" />
                <asp:Parameter Name="contact2" Type="String" />
                <asp:Parameter Name="cell" Type="String" />
                <asp:Parameter Name="hours2" Type="String" />
                <asp:Parameter Name="notes" Type="String" />
                <asp:Parameter Name="idnum" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>
    </asp:Content>
    
    Aspx.cs:
    public void dvEditVendor_ItemUpdating(Object sender, DetailsViewUpdateEventArgs e)
            {
                IOrderedDictionary dic = e.NewValues;
                for (int i = 0; i < dic.Keys.Count; i++)
                {
                    e.NewValues[i] = System.Web.HttpUtility.HtmlEncode(e.NewValues[i].ToString());
                }
            }
    

    The Result:

    Best regards,

    Sam

    Friday, May 17, 2019 6:50 AM