2

外部标记

  <Listeners>
     <Select Handler="Ext.net.DirectMethods.loadcombo2();" />
    </Listeners>

C#

[DirectMethod]
protected void loadcombo2() 
{
    this.ComboBox2.AddItem("List1", "L1");
    this.ComboBox2.AddItem("List2", "L2");

}

如何通过组合框单元格更改调用直接方法?

我收到一个错误

Uncaught TypeError: Object #<Object> has no method 'loadcombo2'
4

2 回答 2

3

我认为这里的最佳做法是使用 Select 直接事件。

将现有的直接方法替换为:

protected void LoadCombo2(object sender, DirectEventArgs e) {
    this.ComboBox1.AddItem("List1", "L1");
    this.ComboBox1.AddItem("List2", "L2");
}

并将监听器替换为:

<DirectEvents>
    <Select OnEvent="LoadCombo2" />
</DirectEvents>
于 2011-12-05T10:19:06.510 回答
2

尝试为 loadcombo2 设置 public 而不是 protected

你可以试试这个代码,它对我来说很好:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!X.IsAjaxRequest) {
            this.Store1.DataSource = new object[] {
                new object[] {"AL", "Alabama", "The Heart of Dixie"},

            };

            this.Store1.DataBind();
        }

    }

    [DirectMethod]
    public void LoadCombo2() {
        this.ComboBox1.AddItem("List1", "L1");
        this.ComboBox1.AddItem("List2", "L2");
    }

</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Comboboxes - Ext.NET Examples</title>
</head>
<body>
    <form id="Form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />

        <ext:Store ID="Store1" runat="server">
            <Reader>
                <ext:ArrayReader>
                    <Fields>
                        <ext:RecordField Name="abbr" />
                        <ext:RecordField Name="state" />
                        <ext:RecordField Name="nick" />
                    </Fields>
                </ext:ArrayReader>
            </Reader>            
        </ext:Store>

        <h2>Not Editable:</h2>

        <ext:ComboBox 
            ID="ComboBox1" 
            runat="server" 
            StoreID="Store1" 
            Editable="false"
            DisplayField="state"
            ValueField="abbr"
            TypeAhead="true" 
            Mode="Local"
            ForceSelection="true"
            EmptyText="Select a state..."
            Resizable="true"
            SelectOnFocus="true"
            >
            <Listeners>
                <Select Handler="DT.Everest.DocFlow.LoadCombo2();" />
            </Listeners>

            </ext:ComboBox>
    </form>
</body>
</html>
于 2011-11-18T06:37:55.947 回答