Monday, 15 September 2014

c# - ObjectDataSource update event not firing, even when I add the parameters in code behind -



c# - ObjectDataSource update event not firing, even when I add the parameters in code behind -

i having problem detailsview not update table. firstly background. have old access scheme (when time) porting asp.net. have written info access layer database object classes phone call access data. thought when port can modify 1 class , should work well. class called trackerdb, , works other gridviews etc.

i have had problem gridview before able solve adding causesvalidation = false definition, detailsview not have that.

here classe want phone call part of objectdatasource:

the class (most of it, there insert , select too)

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; } // , sets of public public int repairid { { homecoming _repairid; } set { _repairid = value; } } public long customerid { { homecoming _customerid; } set { _customerid = value; } } public string contactname { { homecoming _contactname; } set { _contactname = value; } } public string contactemail { { homecoming _contactemail; } set { _contactemail = value; } } public string jobcardnumber { { homecoming _jobcardnumber; } set { _jobcardnumber = value; } } public datetime datelogged { { homecoming _datelogged; } set { _datelogged = value; } } public datetime laststatuschange { { homecoming _laststatuschange; } set { _laststatuschange = value; } } public int machinetypeid { { homecoming _machinetypeid; } set { _machinetypeid = value; } } public string machineserialnumber { { homecoming _machineserialnumber; } set { _machineserialnumber = value; } } public int swopoutmachineid { { homecoming _swopoutmachineid; } set { _swopoutmachineid = value; } } public int machineconditionid { { homecoming _machineconditionid; } set { _machineconditionid = value; } } public bool takenfrother { { homecoming _takenfrother; } set { _takenfrother = value; } } public bool takenbeanlid { { homecoming _takenbeanlid; } set { _takenbeanlid = value; } } public bool takenwaterlid { { homecoming _takenwaterlid; } set { _takenwaterlid = value; } } public bool brokenfrother { { homecoming _brokenfrother; } set { _brokenfrother = value; } } public bool brokenbeanlid { { homecoming _brokenbeanlid; } set { _brokenbeanlid = value; } } public bool brokenwaterlid { { homecoming _brokenwaterlid; } set { _brokenwaterlid = value; } } public int repairfaultid { { homecoming _repairfaultid; } set { _repairfaultid = value; } } public string repairfaultdesc { { homecoming _repairfaultdesc; } set { _repairfaultdesc = value; } } public int repairstatusid { { homecoming _repairstatusid; } set { _repairstatusid = value; } } public int relatedorderid { { homecoming _relatedorderid; } set { _relatedorderid = value; } } public string notes { { homecoming _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 (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 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(); } homecoming _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(); // homecoming _result; } }

}

then asp page:

<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 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" />

and code behind:

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 together other items /// code below added see if info routing works: // if phone call info updates, mode not change, utilize redirect check , works fine // _repair.updaterepair(_repair.repairid, _repair); // response.redirect(string.format("~/pages/repairdetail.aspx?{0}={1}",const_url_request_repairid,_repair.repairid)); }

if phone call update myself , redirect page works fine.

i had feeling ajax messing things created blank page code above, , ran code, gave me error objectdatasource not find non-generic method takes parameters of type 'trackerdotnet.control.repairstbl', added phone call did not require orig_repairid , works:

public string updaterepair(trackerdotnet.control.repairstbl repairitem) { homecoming updaterepair(repairitem, repairitem.repairid); }

not sure why ajax prevents error message

c# code-behind objectdatasource detailsview

No comments:

Post a Comment