[英]Best way to override ext.net combobox
I try to find some examples for overriding ext.net combobox
. 我尝试找到一些覆盖ext.net
combobox
示例。 I need to do this, because I want to use default values for most properties. 我需要这样做,因为我想对大多数属性使用默认值。 But I have a problem.
但是我有一个问题。 I could not to find some examples for
store
, handler
, proxy
and my own listeners
which using in combobox
. 我找不到在
combobox
中使用的store
, handler
, proxy
和我自己的listeners
一些示例。 How can I override it? 如何覆盖? Can anybody give me some examples?
有人可以给我一些例子吗?
AC# class example for own combobox
. 自己的
combobox
AC#类示例。 My thanks. 谢谢
Edit... 编辑...
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
}
My WebForm: 我的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>
But Handler never called. 但是Handler从未打电话。 Why?
为什么?
Ok, I found a problem. 好的,我发现了一个问题。 It was because I didn't place ID for my store like this:
这是因为我没有为商店输入ID,如下所示:
protected override void OnPreRender(EventArgs e)
{
StoreID = _store.ClientID;
base.OnPreRender(e);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.