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

时间:2013-06-18 20:56:39

标签: asp.net vb.net ext.net gridpanel

我正在开发一个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 个答案:

答案 0 :(得分:0)

我知道您正在将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>

P.S。答案的来源是here