覆盖ext.net组合框的最佳方式

时间:2016-06-14 03:14:46

标签: c# asp.net inheritance extjs ext.net

我尝试找到一些覆盖ext.net combobox的示例。我需要这样做,因为我想对大多数属性使用默认值。但我有一个问题。我无法找到storehandlerproxy以及listeners中使用的combobox的一些示例。我怎样才能覆盖它?有人可以给我一些例子吗?

自己combobox的C#类示例。谢谢。

编辑...

public class CombinedComboBox : ComboBox
{
    #region Properties

    private string _handlerAddress;
    private Store _store;
    private StoreParameterCollection _storeParameters;
    private ModelFieldCollection _modelFields;
    private ListenerCollection _listeners;

    public string HandlerAddress
    {
        get { return _handlerAddress; }
        set
        {
            if (!value.StartsWith("/Handlers/"))
                _handlerAddress = "/Handlers/" + value;
            else
                _handlerAddress = value;
        }
    }       

    public StoreParameterCollection StoreParameters
    {
        get { return _storeParameters;  }
        set { _storeParameters = value; }
    }

    public ModelFieldCollection ModelFields
    {
        get { return _modelFields; }
        set { _modelFields = value;  }
    }

    #endregion

    #region ASP.NET Controls Init & Events

    public CombinedComboBox()
    {
        //Базовые автоматические значения, также можно просадить в Init
        HideLabel = false;
        DisplayField = "Name";
        PageSize = 10;
        TypeAhead = true;
        LabelWidth = 160;
        MinChars = 2;
    }

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        BuildStore();

        if (!AllowBlank) AfterLabelTextTpl.Html = "<span style=\"color: red; font - weight: bold\" data-qtip=\"Required\">*</span>";
    }

    private void BuildStore()
    {
        _store = new Store
        {
            AutoLoad = false,
            RemotePaging = true,
            RemoteFilter = true,
            IsPagingStore = true,
            PageSize = PageSize
        };

        _store.Proxy.Add(new AjaxProxy
        {
            Json = true,
            ActionMethods = { Read = HttpMethod.GET },
            Url = HandlerAddress,
            Reader = { new JsonReader { Root = "data", TotalProperty = "total" } }
        });            

        if (_storeParameters != null && _storeParameters.Count > 0)
        {
            foreach (var item in _storeParameters)
            {
                _store.Parameters.Add(item);
            }
        }

        _store.AutoLoadParams.Add(new Parameter("start", "0"));
        _store.AutoLoadParams.Add(new Parameter("limit", PageSize.ToString()));

        Model model = new Model { IDProperty = "Id" };
        model.Fields.Add(new ModelField("Id", ModelFieldType.String));
        model.Fields.Add(new ModelField("Name", ModelFieldType.String));

        if (_modelFields != null && _modelFields.Count > 0)
        {
            foreach (var item in _modelFields)
            {
                model.Fields.Add(item);
            }                
        }
        _store.Model.Add(model);

        Bin.Add(_store);
    }
    #endregion
}

我的WebForm:

<elem:CombinedComboBox                                                 
                                            ID="MyId"
                                            runat="server"
                                            EmptyText="Text"
                                            FieldLabel="Text"
                                            HandlerAddress="/Handlers/OrgStructureDirectionsListHandler.ashx">                                                
                                            <StoreParameters>
                                                <ext:StoreParameter Name="DirectionType" Value="SomeDirection" Mode="Value" />
                                            </StoreParameters>
                                            <Listeners>
                                                <Select Fn="ItemSelected"/>
                                            </Listeners>
                                            </elem:CombinedComboBox>

但是汉德勒从未打电话过。为什么?

1 个答案:

答案 0 :(得分:1)

好的,我发现了一个问题。这是因为我没有为我的商店分配ID:

        protected override void OnPreRender(EventArgs e)
    {
        StoreID = _store.ClientID;
        base.OnPreRender(e);
    }