简体   繁体   English

在 Devexpress ASPxGridView 中查找控件

[英]Finding controls within Devexpress ASPxGridView

I have a code that contains an ASPxGridView and a ASPxCheckBox and Label within in like:我有一个包含 ASPxGridView 和 ASPxCheckBox 和标签的代码,如下所示:


    <dx:ASPxGridView ID="gvTableSearchHomes" runat="server" DataSourceID="XmlHomes" Width="341px"
CssClass="tableViewSearchGrid" ClientInstanceName="gvTableSearchHomes"
AutoGenerateColumns="False" EnableRowsCache="false" KeyFieldName="ID">
<%--<Columns>--%>
    <%-- DXCOMMENT: Within ASPxGridView, add a column whose values will participate in filtering --%>
    <%--<dx:GridViewDataTextColumn FieldName="Address">
        <PropertiesTextEdit NullText="Search your home"></PropertiesTextEdit>
        <Settings AllowAutoFilterTextInputTimer="True" AutoFilterCondition="Contains" />
    </dx:GridViewDataTextColumn>
</Columns>--%>
    <Templates>
     <%--DXCOMMENT: Configure the grid's DataRow template in accordance with data source fields --%>
    <DataRow>
        <div class="gvItem">
            <dx:ASPxCheckBox ID="ChkBookList" runat="server"></dx:ASPxCheckBox>
            <dx:ASPxLabel ID="Address" runat="server" CssClass="address" Text='<%# Utils.ExtractFirstRow(Eval("Address")) %>' />
            <%--<p><dx:ASPxLabel ID="Address2" runat="server" CssClass="address2" Text='<%# Utils.ExtractSecondRow(Eval("Address")) %>' /></p>
            <p><dx:ASPxLabel ID="Price" runat="server" CssClass="price" Text='<%# Utils.GetPrice(Eval("Price")) %>' /></p>--%>
        </div>
    </DataRow>
</Templates>
<SettingsPager Visible="false" PageSize="1000" />
<Settings ShowVerticalScrollBar="True" ShowFilterRow="true" ShowColumnHeaders="false"/>
<SettingsBehavior AutoExpandAllGroups="true" AllowSelectSingleRowOnly="true" AllowSelectByRowClick="true"/>
<ClientSideEvents 
    Init="function(){ hr.TableViewLandscape_Adjust(); }" 
    EndCallback="function(){ hr.TableViewLandscape_Adjust(); }"
    SelectionChanged="OnGvTableSearchHomesSelectedChanged" />
<Styles>
    <SelectedRow ForeColor="White"></SelectedRow>
</Styles>


I am not able to access these cotnrols through C# code.我无法通过 C# 代码访问这些控制。 Can anybody help me.有谁能够帮我。 Please

Check the documentation methods to find controls in different gridview templates.检查文档方法以在不同的 gridview 模板中查找控件。 eg ASPxGridView.FindRowTemplateControl Method例如ASPxGridView.FindRowTemplateControl 方法

Source: http://developmentsolutionsjunction.blogspot.in/2011/11/find-controls-in-dataitemtemplate-of.html来源: http : //developmentsolutionsjunction.blogspot.in/2011/11/find-controls-in-dataitemtemplate-of.html

//markup //标记

    <dx:ASPxGridView ID="grvTest" AutoGenerateColumns="False" runat="server" DataSourceID="SqlDataSource1"
          OnHtmlRowPrepared="grvTest_HtmlRowPrepared" OnHtmlRowCreated="grvTest_HtmlRowCreated">
          <Columns>
              <dx:GridViewDataTextColumn Caption="RowID" Name="colRowID" VisibleIndex="0" Width="20px">
                  <DataItemTemplate>
                       <dx:ASPxLabel ID="lblRowID" runat="server" Text='Label'>
                      </dx:ASPxLabel>
                 </DataItemTemplate>
</dx:GridViewDataTextColumn>

//accessing template control in code-behind //访问代码隐藏中的模板控件

protected void grvTest_HtmlRowCreated(object sender, ASPxGridViewTableRowEventArgs e)
        {
            if (e.RowType != GridViewRowType.Data) return;

            ASPxLabel label = grvTest.FindRowCellTemplateControl(e.VisibleIndex, null,
            "lblRowID") as ASPxLabel;
            label.Text = (e.VisibleIndex + 1).ToString();
        }

example code:示例代码:

ASPxGridView grid = (ASPxGridView)sender;

ASPxPageControl myPages = grid.FindEditFormTemplateControl("CityEditTabs") 
                                                              as ASPxPageControl;

References:参考:
How can I write events for the controls used in my Grid templates如何为网格模板中使用的控件编写事件
Some GridView code snippets to understand gridview concepts 一些 GridView 代码片段来理解 gridview 概念

Identify the VisibleIndex or RowHandle to get the control in particular template that you have created in your markup.标识 VisibleIndex 或 RowHandle 以获取您在标记中创建的特定模板中的控件。

Hope above example will help you to solve your problem.希望上面的例子能帮助你解决你的问题。

thanks I solved mi problem.谢谢我解决了我的问题。 I put this我把这个

Protected Sub GvEncuesta_HtmlRowCreated(sender As Object, e As ASPxGridViewTableRowEventArgs)
    If (e.RowType <> GridViewRowType.Data) Then Return

    Try
        Dim cmbRespuesas As ASPxComboBox = GvEncuesta.FindRowCellTemplateControl(e.VisibleIndex, Nothing, "ASPxCmbRespuestas")

        cmbRespuesas.IncrementalFilteringMode = IncrementalFilteringMode.Contains
        cmbRespuesas.Visible = True
        cmbRespuesas.DataSource = wcfCap.RetrieveRespuestaEncuestaxEstado(1)
        cmbRespuesas.ValueField = "Cod_Respuesta"
        cmbRespuesas.TextField = "Nombre_Respuesta"
        cmbRespuesas.DataBindItems()
    Catch ex As Exception
    End Try
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM