0

我想让单元格品牌代码仅在单击编辑时读取。但是当我使用只读属性时,它变得如此复杂。因为点击新建时,品牌代码无法点击。

这里我的代码

<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 &gt;" />
      <PrevPageButton Text="&lt; 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>
4

3 回答 3

0

您需要处理ASPxGridView.CellEditorInitilaize事件:

protected void MyGridOnCellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e) {
    ASPxGridView gridView = (ASPxGridView).sender;
    e.Editor.ReadOnly = !gridView.IsNewRowEditing && "BrandCode".Equals(e.Column.FieldName);
}
于 2013-01-11T10:55:16.753 回答
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
于 2013-01-14T07:58:47.160 回答
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);
    }
于 2014-04-26T11:22:29.383 回答