在ASPxGridView的DetailRow区域中找到按钮

时间:2017-08-31 14:07:51

标签: asp.net devexpress aspxgridview

我在另一个ASPxGridView中有一个嵌套的ASPxGridView。第二个网格位于DetailRow Template区域。

根据用户的角色,我需要启用/禁用按钮(在服务器端)。

当它们位于GridViewDataColumn区域时,我可以找到然后对按钮执行操作(请参阅buttonDocumentTypeEdit和buttonDocumentSubtypeEdit按钮)。我为此目的使用OnHtmlDataCellPrepared事件。

但我找不到在服务器端找到buttonDocumentSubtypeAdd按钮的方法,该按钮位于DetailRow区域。

ASPxGridView:

<dx:ASPxGridView ID="gridDocumentTypes" ClientInstanceName="gridDocumentTypes" runat="server" AutoGenerateColumns="False"
                    DataSourceID="odsDocumentTypes" KeyFieldName="Id" Width="100%"
                    OnHtmlDataCellPrepared="gridDocumentTypes_OnHtmlDataCellPrepared">
    <Columns>
        <dx:GridViewDataTextColumn Caption="Document Type" FieldName="Name"/>
        <dx:GridViewDataColumn Name="columnDocumentTypeActions">
            <DataItemTemplate>
                <dx:ASPxButton ID="buttonDocumentTypeEdit" runat="server" Text="Edit"/>
            </DataItemTemplate>
        </dx:GridViewDataColumn>
    </Columns>
    <Templates>
        <DetailRow>

            <dx:ASPxButton ID="buttonDocumentSubtypeAdd" ClientInstanceName="buttonDocumentSubtypeAdd" runat="server"
                            Text= "Add Subtype" AutoPostBack="False" UseSubmitBehavior="False">
            </dx:ASPxButton>

            <dx:ASPxGridView ID="gridDocumentSubtypes" runat="server" ClientInstanceName="gridDocumentSubtypes"
                                DataSourceID="GetDocumentSubtypes" KeyFieldName="Id" Width="100%">
                <Columns>
                    <dx:GridViewDataColumn FieldName="Name" Caption="Document Subtype" />

                    <dx:GridViewDataColumn Name="columnDocumentSubtypeActions">
                        <DataItemTemplate>
                            <table>
                                <tr>
                                    <td style="padding-right: 5px">
                                        <dx:ASPxButton ID="buttonDocumentSubtypeEdit" runat="server" Text="Edit">
                                        </dx:ASPxButton>
                                    </td>
                                </tr>
                            </table>
                        </DataItemTemplate>
                    </dx:GridViewDataColumn>
                </Columns>
            </dx:ASPxGridView>
        </DetailRow>
    </Templates>
</dx:ASPxGridView>

服务器代码:

protected void gridDocumentTypes_OnHtmlDataCellPrepared(object sender, ASPxGridViewTableDataCellEventArgs e)
    {
        if (e.DataColumn.Name == "columnDocumentTypeActions")
        {
            var buttonEdit = (ASPxButton)gridDocumentTypes.FindRowCellTemplateControl(e.VisibleIndex, e.DataColumn, "buttonDocumentTypeEdit");

            //TODO: action
        }
    }

0 个答案:

没有答案