Ext.Net:RowExpander:无法在 Codebehind (VB.NET) 中显示嵌套的 GridPanel

Posted

技术标签:

【中文标题】Ext.Net:RowExpander:无法在 Codebehind (VB.NET) 中显示嵌套的 GridPanel【英文标题】:Ext.Net: RowExpander: Unable to display nested GridPanel in Codebehind (VB.NET) 【发布时间】:2013-06-18 20:56:39 【问题描述】:

我正在开发一个 ASP.NET 网站,并且正在使用带有 RowExpander 部分的 GridPanel。 :

<ext:RowExpander ID="RowExpander1" runat="server">
            <Loader ID="Loader1" runat="server" DirectMethod="#DirectMethods.GetGrid" Mode="Component">
                <LoadMask ShowMask="true" />
                <Params>
                    <ext:Parameter Name="id" Value="this.record.getId()" Mode="Raw" />
                </Params>
            </Loader>
        </ext:RowExpander>

在代码隐藏中,名为“GetData”的函数必须动态创建嵌套的 GridPanel,如下所示:

<Ext.Net.DirectMethod()>
Public Function GetGrid(ByVal parameters As Dictionary(Of String, String)) As Object

    Dim data As New List(Of Object)

    For i = 1 To 10
        data.Add(New With .ID = "P" & i, .Name = "Product " & i)
    Next

    Dim config As New Ext.Net.GridPanel.Config

    config.Height = 50
    config.EnableColumnHide = False
    config.StoreID = "Store2"

    Dim store As New Ext.Net.Store
    Dim model As New Ext.Net.Model

    store.ID = "Store2"
    store.DataSource = data
    store.ModelName = "Model2"

    model.ID = "Model2"
    model.IDProperty = "ID"
    model.Fields.Add("ID")
    model.Fields.Add("Name")

    store.Model.Add(model)
    config.Store.Add(store)
    config.StoreID = "Store2"

    Dim column As New Ext.Net.Column
    column.ID = "ColumnModel2"
    column.Text = "Products's Name"
    column.DataIndex = "Name"
    config.ColumnModel.Columns.Add(column)
    config.ColumnModel.Add(column)

    Dim grid As New Ext.Net.GridPanel(config)

    Return Ext.Net.ComponentLoader.ToConfig(grid)

End Function

当我单击 GridPanel 中的“+”时,它会显示一个空网格,即使没有列。其实Ext.Net.ComponentLoader.ToConfig(grid)生成的代码是:

["height":50,"xtype":"grid","columns":,"enableColumnHide":false,"store":"Store2"]

所以我在 GetGrid 函数中做错了。我错过了什么?

我遇到的每个示例都是用 C# 编写的。

【问题讨论】:

【参考方案1】:

我知道您正在将 this C# example 转换为 VB.NET。

好吧,轻声说,我对 VB.NET 不太熟悉。因此,在这种情况下,我使用 C# 到 VB.NET 转换器。例如,the Telerik one。

似乎,VB.NET 没有用于只读属性的对象初始值设定项(不过,我不是 100% 确定),因此,在转换之前,我必须将 C# 代码更改为:

[DirectMethod]
public static string GetGrid(Dictionary<string, string> parameters)

    GridPanel grid = new GridPanel
    
        Height = 200,
        EnableColumnHide = false
    ;

    List<object> data = new List<object>();

    for (int i = 1; i <= 10; i++)
    
        data.Add(new  ID = "P" + i, Name = "Product " + i );
    

    Store store = new Store();

    Model model = new Model()
    
        IDProperty = "ID"
    ;

    model.Fields.Add(new ModelField("ID"));
    model.Fields.Add(new ModelField("Name"));


    store.Model.Add(model);

    store.DataSource = data;
    grid.Store.Add(store);

    grid.ColumnModel.Columns.Add(new Column  Text = "Products's Name", DataIndex = "Name" );

    return ComponentLoader.ToConfig(grid);

将其放入转换器后,稍微修改输出以使其可编译,最后得到一个 VB.NET 示例。

<%@ Page Language="VB" %>

<%@ Import Namespace="System.Collections.Generic" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
    Protected Sub Page_Load(sender As Object, e As EventArgs)
        If Not ExtNet.IsAjaxRequest Then
            Dim data As New List(Of Object)()

            For i As Integer = 1 To 10
                data.Add(New With  _
                    .ID = "S" & i.ToString(), _
                    .Name = "Supplier " & i.ToString() _
                )
            Next

            Me.Store1.DataSource = data
        End If

    End Sub

    <DirectMethod> _
    Public Shared Function GetGrid(parameters As Dictionary(Of String, String)) As String
        Dim grid As New GridPanel() With  _
            .Height = 200, _
            .EnableColumnHide = False _
        

        Dim data As New List(Of Object)()

        For i As Integer = 1 To 10
            data.Add(New With  _
                .ID = "P" & i.ToString(), _
                .Name = "Product " & i.ToString() _
            )
        Next

        Dim store As New Store()

        Dim model As New Model() With  _
            .IDProperty = "ID" _
        

        model.Fields.Add(New ModelField("ID"))
        model.Fields.Add(New ModelField("Name"))


        store.Model.Add(model)

        store.DataSource = data
        grid.Store.Add(store)

        grid.ColumnModel.Columns.Add(New Column() With  _
            .Text = "Products's Name", _
            .DataIndex = "Name" _
        )

        Return ComponentLoader.ToConfig(grid)
    End Function
</script>

<!DOCTYPE html>

<html>
<head runat="server">
    <title>Ext.NET v2 Example</title>
</head>
<body>
    <form runat="server">
        <ext:ResourceManager runat="server" />

        <ext:GridPanel
            runat="server"
            Title="Expander Rows with GridPanel"
            Collapsible="true"
            AnimCollapse="true"
            Icon="Table"
            Width="600"
            Height="450"
            DisableSelection="true">
            <Store>
                <ext:Store ID="Store1" runat="server">
                    <Model>
                        <ext:Model runat="server" IDProperty="ID">
                            <Fields>
                                <ext:ModelField Name="ID" />
                                <ext:ModelField Name="Name" />
                            </Fields>
                        </ext:Model>
                    </Model>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:Column runat="server" Text="Supplier" DataIndex="Name" Flex="1" />
                </Columns>
            </ColumnModel>
            <Plugins>
                <ext:RowExpander runat="server">
                    <Loader runat="server" DirectMethod="#DirectMethods.GetGrid" Mode="Component">
                        <LoadMask ShowMask="true" />
                        <Params>
                            <ext:Parameter Name="id" Value="this.record.getId()" Mode="Raw" />
                        </Params>
                    </Loader>
                </ext:RowExpander>
            </Plugins>
        </ext:GridPanel>
    </form>
</body>
</html>

附:答案来源here。

【讨论】:

虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接的答案可能会失效。

以上是关于Ext.Net:RowExpander:无法在 Codebehind (VB.NET) 中显示嵌套的 GridPanel的主要内容,如果未能解决你的问题,请参考以下文章

ExtJS 仅在条件下显示 RowExpander

将 FormPanel 放入 RowExpander?

无法在 ext.net 网格面板内的组合框中检索和设置值

使用 RowExpander 将普通网格更改为网格

渲染 Grid 面板 Ext.Net 的最后一列

在 ext.net 树面板的特定节点上使用直接事件