Devexpress:aspxgridview in the binding frame (do not use the damned aspxdropdownedit, but with simple gridviewdatacomboboxcolumn)

Source: Internet
Author: User


This damned aspxdropdownedit, always can't solve the problem very well, spent a day without solving. Just revisit a Devexpree official website, found the legendary solution: the original official does not mention the use of Aspxdropdownedit, but highly recommended ComboBox.



The solution is as follows:



1,html Foreground Code



Note: The key is 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="~/App_Themes/Office2003Blue/{0}/styles.css"
CssPostfix="Office2003Blue" Width="100%" KeyFieldName="AppID"
onrowinserting="grvUserGroup_RowInserting"
onrowupdating="grvUserGroup_RowUpdating"
onrowdeleting="grvUserGroup_RowDeleting"
oncelleditorinitialize="grvUserGroup_CellEditorInitialize" >
<ClientSideEvents RowDblClick="function(s, e) {
s.StartEditRow(e.visibleIndex);
}
<Columns>
< DX: gridviewdatacomboboxcolumn caption = "system name" fieldname = "appid"
VisibleIndex="0" >
<PropertiesComboBox ValueType="System.String"  TextField="AppName"
ValueField="AppID" EnableSynchronization="False"
IncrementalFilteringMode="StartsWith" DataSourceID="sqlDataSrcApp" Width="100%">
</PropertiesComboBox>
<EditCellStyle HorizontalAlign="Left">
</EditCellStyle>
</dx:GridViewDataComboBoxColumn>
< DX: gridviewdatacomboxcolumn caption = "user group" fieldname = "groupid"
VisibleIndex="1">
<PropertiesComboBox ValueType="System.String"  TextField="GroupName"
ValueField="GroupID" EnableSynchronization="False"
IncrementalFilteringMode="StartsWith" DataSourceID="sqlDataSrcGroup" Width="100%">
</PropertiesComboBox>
<EditCellStyle HorizontalAlign="Left">
</EditCellStyle>
</dx:GridViewDataComboBoxColumn>
</Columns>
<SettingsBehavior AllowFocusedRow="True" />
<SettingsEditing Mode="PopupEditForm" PopupEditFormHeight="80px"
PopupEditFormHorizontalAlign="WindowCenter" PopupEditFormModal="True"
PopupEditFormVerticalAlign="WindowCenter" PopupEditFormWidth="450px"
EditFormColumnCount="4" />
< settingstext commandcancel = "Cancel" commanddelete = "delete" commandedit = "modify"
Commandnew = "new" commandupdate = "OK" confirmdelete = "are you sure you want to delete" title = "modify user group information"
Popupeditformcaption = "modify user group information" / >
<Styles CssFilePath="~/App_Themes/Office2003Blue/{0}/styles.css"
CssPostfix="Office2003Blue">
<Header HorizontalAlign="Center">
</Header>
</Styles>
</dx:ASPxGridView>

2. Main background code (1)

// if(!) in form_load Enclosing IsPostBack) {-}
// the ellipsis section includes the following

SSQL = "select [AppID],[AppName] from [sysApp]";
SqlDataSrcApp. SelectCommand = sSQL;
SqlDataSrcApp. The ConnectionString = Common. ConfigHelper. GetConfigString (" ConnectionString ");
/ / = Common. Tool. GetDataTable (out sError sSQL);
If (! String. IsNullOrEmpty (sError)) {Common. MessageBox. Show (this, sError); The return; }

SSQL = "select [GroupID],[GroupName] from [sysGroup]";
SqlDataSrcGroup. SelectCommand = sSQL;
SqlDataSrcGroup. The ConnectionString = Common. ConfigHelper. GetConfigString (" ConnectionString ");
If (! String. IsNullOrEmpty (sError)) {Common. MessageBox. Show (this, sError); The return; }
3. Main background code (2)

Protected void grvUserGroup_CellEditorInitialize (object sender, DevExpress. Web. ASPxGridView. ASPxGridViewEditorEventArgs e)
{
String sSQL = string. The Empty;
If (grvUserGroup IsNewRowEditing && e.c. with our fabrication: olumn. FieldName = = "AppID")
{
SSQL = "select [AppID],[AppName] from [sysApp]";
SqlDataSrcApp. SelectCommand = sSQL;
SqlDataSrcApp. The ConnectionString = Common. ConfigHelper. GetConfigString (" ConnectionString ");
/ / = Common. Tool. GetDataTable (out sError sSQL);
If (! String. IsNullOrEmpty (sError)) {Common. MessageBox. Show (this, sError); The return; }
}
Else if (grvUserGroup IsNewRowEditing && e.c. with our fabrication: olumn. FieldName = = "GroupID")
{
SSQL = "select [GroupID],[GroupName] from [sysGroup]";
SqlDataSrcGroup. SelectCommand = sSQL;
SqlDataSrcGroup. The ConnectionString = Common. ConfigHelper. GetConfigString (" ConnectionString ");
If (! String. IsNullOrEmpty (sError)) {Common. MessageBox. Show (this, sError); The return; }
}
}

4, grvUserGroup_RowInserting, grvUserGroup_RowUpdating, grvUserGroup_RowDeleting implementation itself


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.