c# - DevExpress Updating on Gridview with combobox column -
<dx:aspxgridview id="grid" clientinstancename="grid" runat="server" keyfieldname="projectid" width="100%" enablerowscache="false" onrowupdating="grid_rowupdating" autogeneratecolumns="false" oncelleditorinitialize="grid_celleditorinitialize"> <settings showgrouppanel="true" /> <settingsediting mode="inline" /> <columns> <dx:gridviewcommandcolumn visibleindex="0"> <editbutton visible="true" /> </dx:gridviewcommandcolumn> <dx:gridviewdatatextcolumn fieldname="projectid" readonly="true" visibleindex="0"/> <dx:gridviewdatacolumn fieldname="projectname" visibleindex="1" /> <dx:gridviewdatacolumn fieldname="projectinfo" visibleindex="2" /> <dx:gridviewdatacomboboxcolumn caption="project manager" fieldname="userid" visibleindex="3"> <propertiescombobox textfield="domainname" valuefield="userid"> </propertiescombobox> </dx:gridviewdatacomboboxcolumn> </columns> </dx:aspxgridview>
i have aspx file above display data joined tables user , project . user has fields userid , domainname , project has projectmanagerid(fk on userid) projectinfo , projectname how populate data
protected void page_load(object sender, eventargs e) { if (!this.ispostback) { //entity framework query project.include("user").tolist(); grid.datasource = bus.operations.entityoperations.projectoperations.selectallprojects(); grid.databind(); } } //upon edit comboboxes populated protected void grid_celleditorinitialize(object sender, aspxgridvieweditoreventargs e) { if (!grid.isediting || e.column.fieldname != "user.domainname") return; if (e.keyvalue == dbnull.value || e.keyvalue == null) return; object val = grid.getrowvaluesbykeyvalue(e.keyvalue, "projectid"); if (val == dbnull.value) return; int country = (int)val; aspxcombobox combo = e.editor aspxcombobox; fillcitycombo(combo); combo.callback += new callbackeventhandlerbase(cmbcity_oncallback); } protected void fillcitycombo(aspxcombobox cmb) { cmb.datasource= bus.operations.entityoperations.useroperations.selectallprojectmanagers(); cmb.databinditems(); }
and these callback , rowupdating functions
void cmbcity_oncallback(object source, callbackeventargsbase e) { fillcitycombo(source aspxcombobox); } protected void grid_rowupdating(object sender, devexpress.web.data.aspxdataupdatingeventargs e) { aspxgridview gridview = (aspxgridview)sender; int projectid = (int)e.keys[gridview.keyfieldname]; p p = new p(); p.projectname = e.newvalues["projectname"].tostring(); p.projectinfo = e.newvalues["projectinfo"].tostring(); p.projectid = projectid; //user.domainname should inputted int convertable string p.projectmanagerid = int32.parse(((string)e.newvalues["user.domainname"])); bus.operations.entityoperations.projectoperations.updateproject(p); gridview.canceledit(); e.cancel = true; }
now there 2 main problems.
first , minor 1 after selecting project manager combobox , click updating don't see change in web view although database changed , effect can seen after page refresh.
second , major if dont touch combobox , change other fields project name , click update string on rowupdate method cannot converted int. if select combobox , update int userid coming expected.
this 1 of first trials on devexpress , code has lot of mistakes , unnecessary complexity. need better , working code
Comments
Post a Comment