即使我在代码后面添加参数,ObjectDataSource也不会触发更新事件

时间:2014-10-13 16:50:54

标签: c# code-behind objectdatasource detailsview

我遇到一个问题,其中DetailsView不会更新表。首先是一些背景知识。我们有一个旧的访问系统,我慢慢(当我有时间)移植asp.net。我编写了一个数据访问层,数据库对象类调用该层来访问数据。我们的想法是,当我们最终移植时,我可以修改一个类,然后一切都应该运行良好。该类称为TrackerDb,可与其他gridviews等一起使用。

之前我遇到过gridview的问题,但能够通过在定义中添加CausesValidation = false来解决这个问题,但是detailview没有这个问题。

这是我想要作为objectDataSource的一部分调用的classe:

班级(大部分都有插入和全部选择)

namespace TrackerDotNet.control

{

public class RepairsTbl
{

    // internal variable declarations
    private int _RepairID;
    private long _CustomerID;
    private string _ContactName;
    private string _ContactEmail;
    private string _JobCardNumber;
    private DateTime _DateLogged;
    private DateTime _LastStatusChange;
    private int _MachineTypeID;
    private string _MachineSerialNumber;
    private int _SwopOutMachineID;
    private int _MachineConditionID;
    private bool _TakenFrother;
    private bool _TakenBeanLid;
    private bool _TakenWaterLid;
    private bool _BrokenFrother;
    private bool _BrokenBeanLid;
    private bool _BrokenWaterLid;
    private int _RepairFaultID;
    private string _RepairFaultDesc;
    private int _RepairStatusID;
    private int _RelatedOrderID;
    private string _Notes;
    // class definition
    public RepairsTbl()
    {
        _RepairID = 0;
        _CustomerID = 0;
        _ContactName = string.Empty;
        _ContactEmail = string.Empty;
        _JobCardNumber = string.Empty;
        _DateLogged = System.DateTime.Now;
        _LastStatusChange = System.DateTime.Now;
        _MachineTypeID = 0;
        _MachineSerialNumber = string.Empty;
        _SwopOutMachineID = 0;
        _MachineConditionID = 0;
        _TakenFrother = false;
        _TakenBeanLid = true;
        _TakenWaterLid = true;
        _BrokenFrother = false;
        _BrokenBeanLid = false;
        _BrokenWaterLid = false;
        _RepairFaultID = 0;
        _RepairFaultDesc = string.Empty;
        _RepairStatusID = 0;
        _RelatedOrderID = 0;
        _Notes = string.Empty;
    }
    // get and sets of public
    public int RepairID { get { return _RepairID; } set { _RepairID = value; } }
    public long CustomerID { get { return _CustomerID; } set { _CustomerID = value; } }
    public string ContactName { get { return _ContactName; } set { _ContactName = value; } }
    public string ContactEmail { get { return _ContactEmail; } set { _ContactEmail = value; } }
    public string JobCardNumber { get { return _JobCardNumber; } set { _JobCardNumber = value; } }
    public DateTime DateLogged { get { return _DateLogged; } set { _DateLogged = value; } }
    public DateTime LastStatusChange { get { return _LastStatusChange; } set { _LastStatusChange = value; } }
    public int MachineTypeID { get { return _MachineTypeID; } set { _MachineTypeID = value; } }
    public string MachineSerialNumber { get { return _MachineSerialNumber; } set { _MachineSerialNumber = value; } }
    public int SwopOutMachineID { get { return _SwopOutMachineID; } set { _SwopOutMachineID = value; } }
    public int MachineConditionID { get { return _MachineConditionID; } set { _MachineConditionID = value; } }
    public bool TakenFrother { get { return _TakenFrother; } set { _TakenFrother = value; } }
    public bool TakenBeanLid { get { return _TakenBeanLid; } set { _TakenBeanLid = value; } }
    public bool TakenWaterLid { get { return _TakenWaterLid; } set { _TakenWaterLid = value; } }
    public bool BrokenFrother { get { return _BrokenFrother; } set { _BrokenFrother = value; } }
    public bool BrokenBeanLid { get { return _BrokenBeanLid; } set { _BrokenBeanLid = value; } }
    public bool BrokenWaterLid { get { return _BrokenWaterLid; } set { _BrokenWaterLid = value; } }
    public int RepairFaultID { get { return _RepairFaultID; } set { _RepairFaultID = value; } }
    public string RepairFaultDesc { get { return _RepairFaultDesc; } set { _RepairFaultDesc = value; } }
    public int RepairStatusID { get { return _RepairStatusID; } set { _RepairStatusID = value; } }
    public int RelatedOrderID { get { return _RelatedOrderID; } set { _RelatedOrderID = value; } }
    public string Notes { get { return _Notes; } set { _Notes = value; } }

    const string CONST_SQL_SELECTBYREPAIRID = "SELECT CustomerID, ContactName, ContactEmail, JobCardNumber, DateLogged, LastStatusChange, " +
                                           "MachineTypeID, MachineSerialNumber, SwopOutMachineID, MachineConditionID, TakenFrother, " +
                                           "TakenBeanLid, TakenWaterLid, BrokenFrother, BrokenBeanLid, BrokenWaterLid, RepairFaultID, " +
                                           "RepairFaultDesc, RepairsTbl.RepairStatusID, RelatedOrderID, Notes " +
                                           "FROM RepairsTbl WHERE (RepairID = ?)";

    const string CONST_SQL_UPDATE = "UPDATE RepairsTbl " +
                                      "SET CustomerID = ?, ContactName = ?, ContactEmail = ?, JobCardNumber = ?, DateLogged = ?, " +
                                           "LastStatusChange = ?, MachineTypeID = ?, MachineSerialNumber = ?, SwopOutMachineID = ?,  " +
                                           "MachineConditionID = ?, TakenFrother = ?, TakenBeanLid = ?, TakenWaterLid = ?, BrokenFrother = ?, " +
                                           " BrokenBeanLid = ?, BrokenWaterLid = ?, RepairFaultID = ?, RepairFaultDesc = ?, RepairStatusID = ?, " +
                                           " RelatedOrderID = ?, Notes = ? " +
                                      "WHERE (RepairsTbl.RepairID = ?)";
    public RepairsTbl GetRepairById(int pRepairID)
    {
        RepairsTbl _DataItem = null;

        if (pRepairID > 0)
        {
            TrackerDb _TrackerDb = new TrackerDb();
            // params would go here if need
            _TrackerDb.AddWhereParams(pRepairID, DbType.Int32);
            IDataReader _DataReader = _TrackerDb.ReturnDataReader(CONST_SQL_SELECTBYREPAIRID);

            if (_DataReader.Read())
            {
                _DataItem = new RepairsTbl();

                _DataItem.RepairID = pRepairID;
                _DataItem.CustomerID = (_DataReader["CustomerID"] == DBNull.Value) ? 0 : Convert.ToInt64(_DataReader["CustomerID"]);
                _DataItem.ContactName = (_DataReader["ContactName"] == DBNull.Value) ? string.Empty : _DataReader["ContactName"].ToString();
                _DataItem.ContactEmail = (_DataReader["ContactEmail"] == DBNull.Value) ? string.Empty : _DataReader["ContactEmail"].ToString();
                _DataItem.JobCardNumber = (_DataReader["JobCardNumber"] == DBNull.Value) ? string.Empty : _DataReader["JobCardNumber"].ToString();
                _DataItem.DateLogged = (_DataReader["DateLogged"] == DBNull.Value) ? System.DateTime.Now : Convert.ToDateTime(_DataReader["DateLogged"]);
                _DataItem.LastStatusChange = (_DataReader["LastStatusChange"] == DBNull.Value) ? System.DateTime.Now : Convert.ToDateTime(_DataReader["LastStatusChange"]);
                _DataItem.MachineTypeID = (_DataReader["MachineTypeID"] == DBNull.Value) ? 0 : Convert.ToInt32(_DataReader["MachineTypeID"]);
                _DataItem.MachineSerialNumber = (_DataReader["MachineSerialNumber"] == DBNull.Value) ? string.Empty : _DataReader["MachineSerialNumber"].ToString();
                _DataItem.SwopOutMachineID = (_DataReader["SwopOutMachineID"] == DBNull.Value) ? 0 : Convert.ToInt32(_DataReader["SwopOutMachineID"]);
                _DataItem.MachineConditionID = (_DataReader["MachineConditionID"] == DBNull.Value) ? 0 : Convert.ToInt32(_DataReader["MachineConditionID"]);
                _DataItem.TakenFrother = (_DataReader["TakenFrother"] == DBNull.Value) ? false : Convert.ToBoolean(_DataReader["TakenFrother"]);
                _DataItem.TakenBeanLid = (_DataReader["TakenBeanLid"] == DBNull.Value) ? false : Convert.ToBoolean(_DataReader["TakenBeanLid"]);
                _DataItem.TakenWaterLid = (_DataReader["TakenWaterLid"] == DBNull.Value) ? false : Convert.ToBoolean(_DataReader["TakenWaterLid"]);
                _DataItem.BrokenFrother = (_DataReader["BrokenFrother"] == DBNull.Value) ? false : Convert.ToBoolean(_DataReader["BrokenFrother"]);
                _DataItem.BrokenBeanLid = (_DataReader["BrokenBeanLid"] == DBNull.Value) ? false : Convert.ToBoolean(_DataReader["BrokenBeanLid"]);
                _DataItem.BrokenWaterLid = (_DataReader["BrokenWaterLid"] == DBNull.Value) ? false : Convert.ToBoolean(_DataReader["BrokenWaterLid"]);
                _DataItem.RepairFaultID = (_DataReader["RepairFaultID"] == DBNull.Value) ? 0 : Convert.ToInt32(_DataReader["RepairFaultID"]);
                _DataItem.RepairFaultDesc = (_DataReader["RepairFaultDesc"] == DBNull.Value) ? string.Empty : _DataReader["RepairFaultDesc"].ToString();
                _DataItem.RepairStatusID = (_DataReader["RepairStatusID"] == DBNull.Value) ? 0 : Convert.ToInt32(_DataReader["RepairStatusID"]);
                _DataItem.RelatedOrderID = (_DataReader["RelatedOrderID"] == DBNull.Value) ? 0 : Convert.ToInt32(_DataReader["RelatedOrderID"]);
                _DataItem.Notes = (_DataReader["Notes"] == DBNull.Value) ? string.Empty : _DataReader["Notes"].ToString();
            }
            _DataReader.Close();
            _TrackerDb.Close();
        }
        return _DataItem;
    }
    public void UpdateRepair(int orig_RepairID, RepairsTbl RepairItem)
    {
        bool _result = false;
        TrackerDb _TrackerDb = new TrackerDb();

        _TrackerDb.AddParams(RepairItem.CustomerID, DbType.Int64);
        _TrackerDb.AddParams(RepairItem.ContactName, DbType.String);
        _TrackerDb.AddParams(RepairItem.ContactEmail, DbType.String);
        _TrackerDb.AddParams(RepairItem.JobCardNumber, DbType.String);
        _TrackerDb.AddParams(RepairItem.DateLogged, DbType.Date);
        _TrackerDb.AddParams(RepairItem.LastStatusChange, DbType.Date);
        _TrackerDb.AddParams(RepairItem.MachineTypeID, DbType.Int32);
        _TrackerDb.AddParams(RepairItem.MachineSerialNumber, DbType.String);
        _TrackerDb.AddParams(RepairItem.SwopOutMachineID, DbType.Int32);
        _TrackerDb.AddParams(RepairItem.MachineConditionID, DbType.Int32);
        _TrackerDb.AddParams(RepairItem.TakenFrother, DbType.Boolean);
        _TrackerDb.AddParams(RepairItem.TakenBeanLid, DbType.Boolean);
        _TrackerDb.AddParams(RepairItem.TakenWaterLid, DbType.Boolean);
        _TrackerDb.AddParams(RepairItem.BrokenFrother, DbType.Boolean);
        _TrackerDb.AddParams(RepairItem.BrokenBeanLid, DbType.Boolean);
        _TrackerDb.AddParams(RepairItem.BrokenWaterLid, DbType.Boolean);
        _TrackerDb.AddParams(RepairItem.RepairFaultID, DbType.Int32);
        _TrackerDb.AddParams(RepairItem.RepairFaultDesc, DbType.String);
        _TrackerDb.AddParams(RepairItem.RepairStatusID, DbType.Int32);
        _TrackerDb.AddParams(RepairItem.RelatedOrderID, DbType.Int32);
        _TrackerDb.AddParams(RepairItem.Notes, DbType.String);

        _TrackerDb.AddWhereParams(orig_RepairID, DbType.Int32);

        _result = String.IsNullOrEmpty(_TrackerDb.ExecuteNonQuerySQL(CONST_SQL_UPDATE));
        _TrackerDb.Close();

        // return _result;
    }
}

}

然后是ASP页面:

      <asp:DetailsView ID="dvRepairDetail" runat="server" CssClass="TblWhite small" CellPadding="0" CellSpacing="0" DataKeyNames="RepairID" 
    AutoGenerateRows="False" DataSourceID="odsRepairDetail">
    <Fields>
      <asp:TemplateField HeaderText="RepairID" Visible="false">
        <EditItemTemplate>
          <asp:Label ID="lblRepairID" runat="server" Text='<%# Eval("RepairID") %>'></asp:Label>
        </EditItemTemplate>
        <ItemTemplate>
          <asp:Label ID="lblRepairID" runat="server" Text='<%# Bind("RepairID") %>'></asp:Label>
        </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderText="CustomerID">
        <EditItemTemplate>
          <asp:DropDownList ID="ddlCompany" runat="server" DataSourceID="odsCompanys" 
            DataTextField="CompanyName" DataValueField="CustomerID" 
            SelectedValue='<%# Bind("CustomerID") %>'>
          </asp:DropDownList>
        </EditItemTemplate>
        <ItemTemplate>
          <asp:DropDownList ID="ddlCompany" runat="server" DataSourceID="odsCompanys" 
            DataTextField="CompanyName" DataValueField="CustomerID" 
            SelectedValue='<%# Bind("CustomerID") %>'>
          </asp:DropDownList>
        </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderText="ContactName">
        <EditItemTemplate>
          <asp:TextBox ID="tbxContactName" runat="server" Text='<%# Bind("ContactName") %>'></asp:TextBox>
        </EditItemTemplate>
        <ItemTemplate>
          <asp:Label ID="lblContactName" runat="server" Text='<%# Bind("ContactName") %>'></asp:Label>
        </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderText="ContactEmail">
        <EditItemTemplate>
          <asp:TextBox ID="tbxContactEmail" runat="server" Text='<%# Bind("ContactEmail") %>'></asp:TextBox>
        </EditItemTemplate>
        <ItemTemplate>
          <asp:Label ID="lblContactEmail" runat="server" Text='<%# Bind("ContactEmail") %>'></asp:Label>
        </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderText="JobCardNumber" SortExpression="JobCardNumber">
        <EditItemTemplate>
          <asp:TextBox ID="tbxJobCardNumber" runat="server" Text='<%# Bind("JobCardNumber") %>' />
        </EditItemTemplate>
        <ItemTemplate>
          <asp:Label ID="lblJobCardNumber" runat="server" Text='<%# Bind("JobCardNumber") %>' />
        </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderText="DateLogged" Visible="False">
        <EditItemTemplate>
          <asp:TextBox ID="tbxDateLogged" runat="server" Text='<%# Bind("DateLogged") %>'></asp:TextBox>
        </EditItemTemplate>
        <ItemTemplate>
          <asp:Label ID="lblDateLogged" runat="server" Text='<%# Bind("DateLogged") %>'></asp:Label>
        </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderText="LastStatusChange" Visible="False">
        <EditItemTemplate>
          <asp:TextBox ID="tbxLastStatusChange" runat="server" 
            Text='<%# Bind("LastStatusChange") %>'></asp:TextBox>
        </EditItemTemplate>
        <ItemTemplate>
          <asp:Label ID="lblLastStatusChange" runat="server" Text='<%# Bind("LastStatusChange") %>'></asp:Label>
        </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderText="MachineTypeID">
        <EditItemTemplate>
          <asp:DropDownList ID="ddlEquipTypes" runat="server" AppendDataBoundItems="True" 
            DataSourceID="odsEquipTypes" DataTextField="EquipTypeName" DataValueField="EquipTypeId"  >
            <asp:ListItem Text="none" Value="0" />
          </asp:DropDownList>
        </EditItemTemplate>
        <ItemTemplate>
          <asp:DropDownList ID="ddlEquipTypes" runat="server" AppendDataBoundItems="True" 
            DataSourceID="odsEquipTypes" DataTextField="EquipTypeName" DataValueField="EquipTypeId"  >
            <asp:ListItem Text="none" Value="0" />
          </asp:DropDownList>
        </ItemTemplate>
      </asp:TemplateField>
      <asp:BoundField DataField="MachineSerialNumber" 
        HeaderText="MachineSerialNumber" />
      <asp:TemplateField HeaderText="SwopOutMachineID">
        <EditItemTemplate>
          <asp:DropDownList ID="ddlSwopOutMachine" runat="server" DataSourceID="odsCompanyDemos" 
            DataTextField="CompanyName" DataValueField="CustomerID" AppendDataBoundItems="true">
            <asp:ListItem Text="none" Value="0" />
          </asp:DropDownList>
        </EditItemTemplate>
        <ItemTemplate>
          <asp:DropDownList ID="ddlSwopOutMachine" runat="server" DataSourceID="odsCompanyDemos" 
            DataTextField="CompanyName" DataValueField="CustomerID" AppendDataBoundItems="true">
            <asp:ListItem Text="none" Value="0" />
          </asp:DropDownList>
        </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderText="MachineConditionID">
        <EditItemTemplate>
          <asp:TextBox ID="TextBox4" runat="server" 
            Text='<%# Bind("MachineConditionID") %>'></asp:TextBox>
        </EditItemTemplate>
        <ItemTemplate>
          <asp:Label ID="Label4" runat="server" Text='<%# Bind("MachineConditionID") %>'></asp:Label>
        </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderText="FrotherTaken">
        <EditItemTemplate>
          <asp:CheckBox ID="cbxTakenFrother" runat="server" Checked='<%# Bind("TakenFrother") %>'
            Text="Frother" TextAlign="Left" />&nbsp;&nbsp;&nbsp;&nbsp;
        </EditItemTemplate>
        <ItemTemplate>
          <asp:CheckBox ID="cbxTakenFrother" runat="server" Checked='<%# Bind("TakenFrother") %>'
            Text="Frother" TextAlign="Left" />&nbsp;&nbsp;&nbsp;&nbsp;
        </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderText="BeanLidTaken">
        <EditItemTemplate>
          <asp:CheckBox ID="cbxTakenBeanLid" runat="server" Checked='<%# Bind("TakenBeanLid") %>' 
            Text="BeanLid" TextAlign="Left" />&nbsp;&nbsp;&nbsp;&nbsp;
        </EditItemTemplate>
        <ItemTemplate>
          <asp:CheckBox ID="cbxTakenBeanLid" runat="server" Checked='<%# Bind("TakenBeanLid") %>'
            Text="BeanLid" TextAlign="Left" />
        </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderText="WaterLidTaken">
        <EditItemTemplate>
          <asp:CheckBox ID="cbxWaterLidTaken" runat="server" Checked='<%# Bind("TakenWaterLid") %>'
            Text="WaterLid" TextAlign="Left" />
        </EditItemTemplate>
        <ItemTemplate>
          <asp:CheckBox ID="cbxWaterLidTaken" runat="server" Checked='<%# Bind("TakenWaterLid") %>'
            Text="WaterLid" TextAlign="Left" />
        </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderText="BrokenFrother">
        <EditItemTemplate>
          <asp:CheckBox ID="CheckBox4" runat="server" 
            Checked='<%# Bind("BrokenFrother") %>' />
        </EditItemTemplate>
        <ItemTemplate>
          <asp:CheckBox ID="CheckBox4" runat="server" 
            Checked='<%# Bind("BrokenFrother") %>' Enabled="false" />
        </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderText="BrokenBeanLid">
        <EditItemTemplate>
          <asp:CheckBox ID="CheckBox5" runat="server" 
            Checked='<%# Bind("BrokenBeanLid") %>' />
        </EditItemTemplate>
        <ItemTemplate>
          <asp:CheckBox ID="CheckBox5" runat="server" 
            Checked='<%# Bind("BrokenBeanLid") %>' Enabled="false" />
        </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderText="BrokenWaterLid">
        <EditItemTemplate>
          <asp:CheckBox ID="CheckBox6" runat="server" 
            Checked='<%# Bind("BrokenWaterLid") %>' />
        </EditItemTemplate>
        <ItemTemplate>
          <asp:CheckBox ID="CheckBox6" runat="server" 
            Checked='<%# Bind("BrokenWaterLid") %>' Enabled="false" />
        </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderText="RepairFaultID">
        <EditItemTemplate>
          <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("RepairFaultID") %>'></asp:TextBox>
        </EditItemTemplate>
        <ItemTemplate>
          <asp:DropDownList ID="ddlRepairFault" runat="server" AppendDataBoundItems="True" 
            DataSourceID="odsRepairFaults" DataTextField="RepairFaultDesc" DataValueField="RepairFaultID" 
            SelectedValue='<%# Bind("RepairFaultID") %>'>
            <asp:ListItem Text="none" Value="0" />
          </asp:DropDownList>
        </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderText="RepairFaultDesc">
        <EditItemTemplate>
          <asp:TextBox ID="tbxRepairFaultDesc" runat="server" Text='<%# Bind("RepairFaultDesc") %>' 
            TextMode="MultiLine" Width="98%" />
        </EditItemTemplate>
        <ItemTemplate>
          <asp:Label ID="lblRepairFaultDesc" runat="server" Text='<%# Bind("RepairFaultDesc") %>' />
        </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderText="RepairStatusID">
        <EditItemTemplate>
          <asp:DropDownList ID="ddlRepairStatuses" runat="server" AppendDataBoundItems="True" 
            DataSourceID="odsRepairStatuses" DataTextField="RepairStatusDesc" DataValueField="RepairStatusID" 
            SelectedValue='<%# Bind("RepairStatusID") %>' >
            <asp:ListItem Text="none" Value="0" />
          </asp:DropDownList>
        </EditItemTemplate>
        <ItemTemplate>
          <asp:DropDownList ID="ddlRepairStatuses" runat="server" AppendDataBoundItems="True" 
            DataSourceID="odsRepairStatuses" DataTextField="RepairStatusDesc" DataValueField="RepairStatusID" 
            SelectedValue='<%# Bind("RepairStatusID") %>' >
            <asp:ListItem Text="none" Value="0" />
          </asp:DropDownList>
        </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderText="RelatedOrderID" Visible="False">
        <EditItemTemplate>
          <asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("RelatedOrderID") %>'></asp:TextBox>
        </EditItemTemplate>
        <ItemTemplate>
          <asp:Label ID="Label6" runat="server" Text='<%# Bind("RelatedOrderID") %>'></asp:Label>
        </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderText="Notes">
        <EditItemTemplate>
          <asp:TextBox ID="tbxNotes" runat="server" Text='<%# Bind("Notes") %>' TextMode="MultiLine"
            Width="98%" />
        </EditItemTemplate>
        <ItemTemplate>
          <asp:Label ID="lblNotes" runat="server" Text='<%# Bind("Notes") %>'></asp:Label>
        </ItemTemplate>
      </asp:TemplateField>
      <asp:CommandField ShowEditButton="True" />
    </Fields>
    <EmptyDataTemplate>
      <h2>New Item for Repair</h2>
      <br />
      <table class="TblDetailZebra">
        <tr>
          <td>Customer</td>
          <td>
          <asp:DropDownList ID="ddlCompanies" runat="server" DataSourceID="odsCompanys" 
            DataTextField="CompanyName" DataValueField="CustomerID" AppendDataBoundItems="true"  >
              <asp:ListItem Selected="True" Value="0">none</asp:ListItem>
            </asp:DropDownList>
          </td>
        </tr>
        <tr>
          <td colspan="2">&nbsp;</td>
        </tr>
        <tr>
          <td class="rowC" colspan="2" valign="middle" align="center">
            <asp:Button ID="btnInsert" Text="Insert" runat="server" OnClick="btnInsert_Click" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Button ID="btnCancel" Text="Cancel" runat="server" />
          </td>
        </tr>
    </EmptyDataTemplate>
  </asp:DetailsView>
  <asp:Label ID="lblThusRepairID" runat="server" Visible="true" />

背后的代码:

    public void RepairUpdating(object source, ObjectDataSourceMethodEventArgs e)
{
    RepairsTbl _Repair = new RepairsTbl();

    _Repair.RepairID = Convert.ToInt32(lblThusRepairID.Text);
    e.InputParameters["orig_RepairID"] = _Repair.RepairID;

    DropDownList _ddlCompany = (DropDownList)dvRepairDetail.FindControl("ddlCompany");
    _Repair.CustomerID = Convert.ToInt64(_ddlCompany.SelectedValue);
    TextBox _tbxContactName = (TextBox)dvRepairDetail.FindControl("tbxContactName");
    _Repair.ContactName = _tbxContactName.Text;
    TextBox _tbxContactEmail = (TextBox)dvRepairDetail.FindControl("tbxContactEmail");
    _Repair.ContactEmail = _tbxContactEmail.Text;
    TextBox _tbxJobCardNumber = (TextBox)dvRepairDetail.FindControl("tbxJobCardNumber");
    _Repair.JobCardNumber = _tbxJobCardNumber.Text;
    e.InputParameters["RepairItem"] = _Repair;
    /// --- add other items 

    /// this code below was just added to see if the data routing works:
    // if I call this the data updates, but the mode does not change, so I use a redirect to check and that works fine
    // _Repair.UpdateRepair(_Repair.RepairID, _Repair);
    //      Response.Redirect(String.Format("~/Pages/RepairDetail.aspx?{0}={1}",CONST_URL_REQUEST_REPAIRID,_Repair.RepairID));

}

如果我自己调用更新,然后重定向页面,则可以正常工作。

1 个答案:

答案 0 :(得分:0)

我有一种感觉,AJAX搞砸了所以我创建了一个空白页面,只有上面的代码,然后运行代码,它给了我一个错误,ObjectDataSource找不到一个非泛型的方法,它接受类型的参数'TrackerDotNet.control.RepairsTbl',所以我添加了一个不需要orig_RepairID的调用,现在它可以工作:

公共字符串UpdateRepair(TrackerDotNet.control.RepairsTbl RepairItem) {return UpdateRepair(RepairItem,RepairItem.RepairID); }

不确定为什么Ajax会阻止错误消息