我想在单击编辑时才读取单元品牌代码。但是,当我使用属性只读它变得如此复杂。因为点击新建时,品牌代码无法点击。
这是我的代码
<dx:ASPxGridView id="gvBrand" runat="server" CssPostfix="Aqua" SettingsBehavior-ConfirmDelete="true" CssFilePath="~/App_Themes/styles.css" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" KeyFieldName="BrandCode" >
<Styles CssPostfix="Aqua" CssFilePath="~/App_Themes/styles.css">
<LoadingPanel ImageSpacing="8px" />
</Styles>
<SettingsPager>
<AllButton Text="All" />
<NextPageButton Text="Next >" />
<PrevPageButton Text="< Prev" />
</SettingsPager>
<SettingsText CommandUpdate="Save" />
<ImagesFilterControl>
<LoadingPanel Url="~/App_Themes/Editors/Loading.gif"></LoadingPanel>
</ImagesFilterControl>
<Images SpriteCssFilePath="~/App_Themes/{0}/sprite.css">
<LoadingPanelOnStatusBar Url="~/App_Themes/GridView/gvLoadingOnStatusBar.gif"> </LoadingPanelOnStatusBar>
<LoadingPanel Url="~/App_Themes/GridView/Loading.gif"></LoadingPanel>
</Images>
<StylesEditors>
<CalendarHeader Spacing="1px"></CalendarHeader>
<ProgressBar Height="25px"></ProgressBar>
</StylesEditors>
<SettingsLoadingPanel ImagePosition="Top" />
<Settings ShowFilterRow="True" ShowGroupPanel="true" />
<Columns>
<dx:GridViewCommandColumn VisibleIndex="0">
<EditButton Visible="True" />
<NewButton Visible="True" />
<DeleteButton Visible="True" />
</dx:GridViewCommandColumn>
<dx:GridViewDataTextColumn FieldName="BrandCode" VisibleIndex="1" Caption="Brand Code"
EditCellStyle-HorizontalAlign="Left" >
<EditFormSettings Visible="True" ColumnSpan="1" />
<PropertiesTextEdit MaxLength="3" Width="35px">
<ValidationSettings SetFocusOnError="True">
<RequiredField IsRequired="True" />
</ValidationSettings>
</PropertiesTextEdit>
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="BrandName" VisibleIndex="2"
Caption="Brand Name" >
<EditFormSettings ColumnSpan="2" />
<PropertiesTextEdit MaxLength="50">
<ValidationSettings SetFocusOnError="True">
<RequiredField IsRequired="True" />
</ValidationSettings>
</PropertiesTextEdit>
</dx:GridViewDataTextColumn>
<dx:GridViewDataCheckColumn FieldName="isBlock" Visible="false"
EditCellStyle-HorizontalAlign="Left" >
<EditFormSettings Visible="true" VisibleIndex="3" Caption="Block"/>
</dx:GridViewDataCheckColumn>
</Columns>
</dx:ASPxGridView>
答案 0 :(得分:0)
您需要处理ASPxGridView.CellEditorInitilaize事件:
protected void MyGridOnCellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e) {
ASPxGridView gridView = (ASPxGridView).sender;
e.Editor.ReadOnly = !gridView.IsNewRowEditing && "BrandCode".Equals(e.Column.FieldName);
}
答案 1 :(得分:0)
感谢我昨天刚刚找到的答案。
VB.NET
Protected Sub gvBrand_CellEditorInitialize(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxGridView.ASPxGridViewEditorEventArgs) Handles gvBrand.CellEditorInitialize
If (gvBrand.IsNewRowEditing) Then
Return
End If
If (e.Column.FieldName = "BrandCode") Then
e.Editor.ReadOnly = True
End If
End Sub
答案 2 :(得分:0)
在内联模式下,e.Editor.ReadOnly不能为我工作,但是 设置e.Editor.Enabled做了:
protected void OnCellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e)
{
List<string> editableFields = new List<string> {"Status"};
e.Editor.Enabled = editableFields.Contains(e.Column.FieldName);
}