开发者

Drop down in detailsview not updating to database

I have fields for a contact. 3 of those fields are drop downs to values from another table in the database. For example, Contacts has the foreign key for departmentid which pulls from the department table to get the description. But when i click the Edit and update, this does not update my database. It acts like nothing happened.

EDIT: Just noticed this, but when i change the name and click update. I get an error telling me that EmployerCode cannot be set to null. I know that the database is set to not nullable. But i do not understand why the original value is not being pulled. When i load the contact, all three of the drop downs have values from the database loaded. Although i am seeing that all three are displaying the first item in the table and not the item the contact has in it's values. But when editing the contact, it acts like those values are not loaded and are just null.

<asp:DetailsView ID="detailsViewContact" runat="server" Height="90px" Width="293px" 
DataSourceID="ContactDataSource" AutoGenerateRows="False" 
BackColor="#FFCC66" BorderStyle="None" BorderWidth="0px" CellPadding="3" 
DataKeyNames="ContactID" Font-Bold="True" HorizontalAlign="Center">
<CommandRowStyle BackColor="White" BorderColor="White" Font-Bold="True" 
  Font-Size="Large" HorizontalAlign="Center" />
<Fields>
  <asp:BoundField DataField="SSOID" HeaderText="SSOID" 
    SortExpression="SSOID" />
  <asp:BoundField DataField="FirstName" HeaderText="FirstName" 
    SortExpression="FirstName" />
  <asp:BoundField DataField="Lastname" HeaderText="Lastname" 
    SortExpression="Lastname" />
  <asp:BoundField DataField="Address" HeaderText="Address" 
    SortExpression="Address" />
  <asp:BoundField DataField="City" HeaderText="City" 
    SortExpression="City" />
  <asp:BoundField DataField="State" HeaderText="State" 
    SortExpression="State" />
  <asp:BoundField DataField="ZipCode" HeaderText="ZipCode" 
    SortExpression="ZipCode" />
  <asp:BoundField DataField="EmailAddress" HeaderText="EmailAddress" 
    SortExpression="EmailAddress" />
  <asp:TemplateField HeaderText="AccessRightID" SortExpression="AccessRightID">
    <EditItemTemplate>
      <asp:DropDownList ID="DropDownList2" runat="server" 
        DataSourceID="AccessRightDataSource" DataTextField="AccessRightDescription" 
        DataValueField="AccessRightID">
      </asp:DropDownList>
    </EditItemTemplate>
    <InsertItemTemplate>
      <asp:DropDownList ID="DropDownList3" runat="server" 
        DataSourceID="AccessRightDataSource" DataTextField="AccessRightDescription" 
        DataValueField="AccessRightID">
      </asp:DropDownList>
    </InsertItemTemplate>
    <ItemTemplate>
      <asp:DropDownList ID="DropDownList10" Enabled="false" runat="server" 
        DataSourceID="AccessRightDataSource" DataTextField="AccessRightDescription" 
        DataValueField="AccessRightID">
      </asp:DropDownList>
    </ItemTemplate>
  </asp:TemplateField>
  <asp:TemplateField HeaderText="EmployerCode" SortExpression="EmployerCode">
    <EditItemTemplate>
      <asp:DropDownList ID="DropDownList5" runat="server" 
        DataSourceID="EmployerDataSource" DataTextField="EmployerName" 
        DataValueField="EmployerCode">
      </asp:DropDownList>
    </EditItemTemplate>
    <InsertItemTemplate>
      <asp:DropDownList ID="DropDownList6" runat="server" 
        DataSourceID="EmployerDataSource" DataTextField="EmployerName" 
        DataValueField="EmployerCode">
      </asp:DropDownList>
    </InsertItemTemplate>
    <Ite开发者_StackOverflowmTemplate>
      <asp:DropDownList ID="DropDownList4" Enabled="false" runat="server" 
        DataSourceID="EmployerDataSource" DataTextField="EmployerName" 
        DataValueField="EmployerCode">
      </asp:DropDownList>
    </ItemTemplate>
  </asp:TemplateField>
  <asp:TemplateField HeaderText="DepartmentID" SortExpression="DepartmentID">
    <EditItemTemplate>
      <asp:DropDownList ID="DropDownList8" runat="server" 
        DataSourceID="DepartmentDataSource" DataTextField="Description" 
        DataValueField="DepartmentID">
      </asp:DropDownList>
    </EditItemTemplate>
    <InsertItemTemplate>
      <asp:DropDownList ID="DropDownList9" runat="server" 
        DataSourceID="DepartmentDataSource" DataTextField="Description" 
        DataValueField="DepartmentID">
      </asp:DropDownList>
    </InsertItemTemplate>
    <ItemTemplate>
      <asp:DropDownList ID="DropDownList7" Enabled="false" runat="server" 
        DataSourceID="DepartmentDataSource" DataTextField="Description" 
        DataValueField="DepartmentID">
      </asp:DropDownList>
    </ItemTemplate>
  </asp:TemplateField>
  <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
    ShowInsertButton="True" />
</Fields>

here are my datasources

<asp:EntityDataSource ID="EmployerDataSource" runat="server" 
ConnectionString="name=WorkStudyEntities" 
DefaultContainerName="WorkStudyEntities" EnableFlattening="False" 
EntitySetName="Employers" EnableUpdate="True">


It looks like this was a fluke somehow. I redid the page and it all worked correctly

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜