This damn aspxdropdownedit cannot solve the problem well, and it took a whole day to solve it. Just now, I visited the devexpree website and found the legendary solution: I did not recommend using aspxdropdownedit, but recommended ComboBox.
The solution is as follows:
1. html front-end code
Note: The key lies in sqldatasource, fieldname, textfield, valuefield, keyfieldname
<Asp: sqldatasource id = "sqldatasrcapp" runat = "server"> </ASP: sqldatasource> <asp: sqldatasource id = "sqldatasrcgroup" runat = "server"> </ASP: sqldatasource> <DX: aspxgridview id = "grvusergroup" runat = "server" autogeneratecolumns = "false" clientidmode = "autoid" cssfilepath = "~ /Configure/office2003blue/{0}/styles.css "csspostfix =" office2003blue "width =" 100% "keyfieldname =" appid "onrowinserting =" inline "onrowupdating =" inline "onrowdeleting =" begin "oncelleditorinitialize =" grvusergroup_celleditorinitialize "> <clientsideevents rowdblclick =" function (s, e) {S. starteditrow (E. visibleindex);} "/> <columns> <DX: gridviewdata Comboboxcolumn caption = "system name" fieldname = "appid" visibleindex = "0"> <propertiescombobox valuetype = "system. string "textfield =" appname "valuefield =" appid "enablesynchronization =" false "placement =" startswith "performanceid =" sqldatasrcapp "width =" 100% "> </propertiescombobox> <editcellstyle horizontalal = "Left"> </editcellstyle> </dx: gridviewdatacomboboxcolumn> <DX: gridviewdatacomboboxco Lumn caption = "User Group" fieldname = "groupid" visibleindex = "1"> <propertiescombobox valuetype = "system. string "textfield =" groupname "valuefield =" groupid "placement =" false "placement =" startswith "performanceid =" sqldatasrcgroup "width =" 100% "> </propertiescombobox> <editcellstyle horizontalalign = "Left"> </editcellstyle> </dx: gridviewdatacomboboxcolumn> </columns> <settingsbehavior Authorization = "true"/> <settingsediting mode = "popupeditform" popupeditformheight = "80px" placement = "windowcenter" popupeditformmodal = "true" placement = "windowcenter" placement = "450px" editformcolumncount = "4"/> <settingstext commandcancel = "cancel" commanddelete = "delete" commandedit = "modify" commandnew = "new" commandupdate = "OK" confirmdelete = "are you sure you want to delete? "Title =" modifying user group information" Popupeditformcaption = "Modify user group information"/> <styles cssfilepath = "~ /App_themes/office2003blue/{0}/styles.css "csspostfix =" office2003blue ">
2. Main background code (1)
// If (! This. ispostback) {----} // The ellipsis contains the following content: ssql = "select [appid], [appname] from [sysapp]"; sqldatasrcapp. selectcommand = ssql; sqldatasrcapp. connectionstring = Common. confighelper. getconfigstring ("connectionstring"); // = Common. tool. getdatatable (Out serror, ssql); If (! String. isnullorempty (serror) {common. messageBox. show (this, serror); return;} ssql = "select [groupid], [groupname] from [sysgroup]"; sqldatasrcgroup. selectcommand = ssql; sqldatasrcgroup. connectionstring = Common. confighelper. getconfigstring ("connectionstring"); If (! String. isnullorempty (serror) {common. MessageBox. Show (this, serror); return ;}
3. Main background code (2)
protected void grvUserGroup_CellEditorInitialize(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewEditorEventArgs e) { string sSQL = string.Empty; if (grvUserGroup.IsNewRowEditing && e.Column.FieldName == "AppID") { sSQL = "select [AppID],[AppName] from [sysApp]"; sqlDataSrcApp.SelectCommand = sSQL; sqlDataSrcApp.ConnectionString = Common.ConfigHelper.GetConfigString("ConnectionString"); //= Common.Tool.GetDataTable(out sError, sSQL); if (!string.IsNullOrEmpty(sError)) { Common.MessageBox.Show(this, sError); return; } } else if (grvUserGroup.IsNewRowEditing && e.Column.FieldName == "GroupID") { sSQL = "select [GroupID],[GroupName] from [sysGroup]"; sqlDataSrcGroup.SelectCommand = sSQL; sqlDataSrcGroup.ConnectionString = Common.ConfigHelper.GetConfigString("ConnectionString"); if (!string.IsNullOrEmpty(sError)) { Common.MessageBox.Show(this, sError); return; } } }
4. grvusergroup_rowinserting, grvusergroup_rowupdating, and grvusergroup_rowdeleting