【问题标题】:Find control in devexpress gridview Templates DetailRow在 devexpress gridview 模板 DetailRow 中查找控件
【发布时间】:2012-04-18 14:11:58
【问题描述】:

我想在我的 gridview.Template 详细信息行中按 id 查找控件

        bool IsAllAud = false;
        var item = (CheckBox)VendorsGrid.Templates.DetailRow.FindControl("CBIsAllAudience");
        IsAllAud = item.Checked;
        if (IsAllAud)
        {

        }
<dx:ASPxGridView ID="rt" ClientInstanceName="rt" runat="server"
            AutoGenerateColumns="false" DataSourceID="rtt" KeyFieldName="ID" Width="100%">
            <SettingsDetail AllowOnlyOneMasterRowExpanded="true" />
            <Columns>
                <dx:GridViewDataTextColumn FieldName="Name" Caption="Name" />
            </Columns>
            <Templates>
                <DetailRow>
                    <asp:CheckBox ID="CBIsAllAudience" runat="server" />
...

【问题讨论】:

  • 您能对您遇到的问题多解释一下吗?您发布的代码有什么问题?
  • var item = (CheckBox)VendorsGrid.Templates.DetailRow.FindControl("CBIsAllAudience");这是我需要做的,但这是编译错误,因为 VendorsGrid.Templates.DetailRow 没有 FindControl() 函数

标签: c# asp.net .net gridview findcontrol


【解决方案1】:

由于这是 DetailRow,您需要致电 ASPxGridView.FindDetailRowTemplateControl Method

var item = VendorsGrid.FindDetailRowTemplateControl(index, "CBIsAllAudience");

【讨论】:

    【解决方案2】:

    在控制事件里写这段代码就行了

    {
     for (int i = 0; i < gvVndInvoiceDevExp.VisibleRowCount ; i++)
                {
                    GridViewDataColumn col1 = gvVndInvoiceDevExp.Columns[0] as GridViewDataColumn;
                    GridViewDataColumn col2 = gvVndInvoiceDevExp.Columns[8] as GridViewDataColumn;
                    CheckBox chk = gvVndInvoiceDevExp.FindRowCellTemplateControl(i, col1, "chk") as CheckBox;
                    ASPxCheckBox chkIsVal = gvVndInvoiceDevExp.FindRowCellTemplateControl(i, col2, "chkIsVal") as ASPxCheckBox;
    
                    if (chk.Checked == true)
                    {
                        chkIsVal.Enabled = true;
    
                    }
                    else
                    {
                        chkIsVal.Enabled = false;
    
                    }
    
                }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-20
      • 2012-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多