如何在按钮单击时找到嵌套到ASPXGridview中的控件

时间:2011-08-23 11:46:23

标签: asp.net devexpress aspxgridview

我的ASPXGridview,DetailRow视图中有一个文本框和按钮。因此,当它扩展时,我需要输入文本并单击按钮,然后在服务器端从文本框中获取值。

这是我的代码。问题是在回发的某个地方,我正在失去文本值。所以文本框是空的

 protected void Button1_Click(object sender, EventArgs e)
    {

        ASPxGridView grid = EmailGridView;

        for (int i = 0; i < grid.VisibleRowCount; i++)
        {
            var txtDescription = (ASPxMemo)grid.FindDetailRowTemplateControl(i, "txtDescription");

            if(txtDescription != null)
            {
                var text = txtDescription.Text;
            }
        }
    }

<dxwgv:ASPxGridView ID="EmailGridView" KeyFieldName="ThreadId" runat="server" AutoGenerateColumns="False"
OnHtmlRowCreated="EmailGridView_HtmlRowCreated" SettingsDetail-AllowOnlyOneMasterRowExpanded="true"
SettingsBehavior-ConfirmDelete="true" OnHtmlRowPrepared="EmailGridView_HtmlRowPrepared"
OnRowDeleted="EmailGridView_RowDeleted">
<SettingsBehavior ConfirmDelete="True" />
<Columns>
    <dxwgv:GridViewDataTextColumn Caption="ID" FieldName="Id" VisibleIndex="0">
    </dxwgv:GridViewDataTextColumn>

    <dxwgv:GridViewCommandColumn VisibleIndex="5" Caption=" ">
        <DeleteButton Visible="True">
        </DeleteButton>
    </dxwgv:GridViewCommandColumn>
</Columns>
<SettingsDetail ShowDetailRow="true" />
<SettingsBehavior ConfirmDelete="True" />
<SettingsDetail AllowOnlyOneMasterRowExpanded="True" ShowDetailRow="True" />
<Templates>
    <DetailRow>
        <dxwgv:ASPxGridView ID="EmailSubGridView" Width="750px" OnBeforePerformDataSelect="EmailSubGridView_BeforePerformDataSelect"
            runat="server" AutoGenerateColumns="False" 
            onhtmlrowcreated="EmailSubGridView_HtmlRowCreated">
            <Columns>
                <dxwgv:GridViewDataTextColumn Caption="MessFrom" FieldName="MessFrom">
                </dxwgv:GridViewDataTextColumn>
                <dxwgv:GridViewDataTextColumn Caption="Message" FieldName="Message">
                </dxwgv:GridViewDataTextColumn>
                <dxwgv:GridViewDataTextColumn Caption="SendDtm" FieldName="SendDtm">
                </dxwgv:GridViewDataTextColumn>
            </Columns>
            <StylesEditors>
                <ProgressBar Height="25px">
                </ProgressBar>
            </StylesEditors>
        </dxwgv:ASPxGridView>


            <dx:ASPxMemo ID="txtDescription" runat="server" Width="170px" Height="71px"></dx:ASPxMemo>

        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Reply" />
    </DetailRow>
</Templates>

2 个答案:

答案 0 :(得分:0)

康尼,

ASPxGridView内置了回调,因此我建议使用该方法,因为它更容易,它可以为您提供更好的用户体验。您正在使用的find方法需要visiblerowindex。

看一下这个code central示例,了解如何从服务器获取数据:

How to bind the detail GridView to data based on the end-user input

答案 1 :(得分:0)

如果您在展开ASPxGridview时需要这些流程,则应使用DetailRowExpandedChanged事件。

当您展开 崩溃您的ASPxGridview时,此活动有效。

Mehul's实际上这种情况非常好。之后,如果您仍然遇到问题,可以在Devexpress Support中提出问题。他们真的很有帮助,也很快。