Hlodvig
Nov 26, 2013, 5:48 PM
So I created server control inherited from the SelectBox which will pre-populate data etc...
Functionality was copied from the old web control, however...
using Ext.Net;
using RdC.Resources;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Web.UI;
namespace RdC.Front.ServerControls
{
[ToolboxData("<{0}:RefSelectBox runat=server></{0}:RefSelectBox>")]
public class RefSelectBox : SelectBox
{
public Object DataSource { get; set; }
public int? SelectedValue
{
get
{
int res;
if (this.SelectedItem != null && int.TryParse(this.SelectedItem.Value, out res))
{
return res;
}
else {
return null;
}
}
set
{
this.Select(value.ToString());
}
}
public RefSelectBox()
{
this.ListConfig = new BoundList
{
Width = 100
};
this.IndicatorTip = ResourcesManager.GetLabel("RefLbx_IndicatorTip");
this.EmptyText = ResourcesManager.GetLabel("RefLbx_EmptyText");
}
protected override void OnInit(System.EventArgs e)
{
base.OnInit(e);
}
public override void DataBind()
{
if (DataSource != null)
{
Type l_sourceType = DataSource.GetType();
if (l_sourceType.IsGenericType && l_sourceType.GetGenericTypeDefinition() == typeof(List<>))
{
IList l_list = DataSource as IList;
if (l_list != null)
{
foreach (object l_object in l_list)
{
Type l_type = l_object.GetType();
PropertyInfo l_idProp = l_type.GetProperty("Id");
PropertyInfo l_labelleProp = l_type.GetProperty("Libelle");
object l_idValue = l_idProp.GetValue(l_object, null);
object l_labelleValue = l_labelleProp.GetValue(l_object, null);
this.Items.Add(new ListItem
{
Text = l_labelleValue.ToString(),
Value = l_idValue.ToString()
});
}
}
}
}
}
}
}
and I add this control to some FormPanel, which is inside of web control
<ext:FormPanel runat="server" ID="MaSocieteFormPanel" Layout="FormLayout" AutoDoLayout="true" Border="false">
<FieldDefaults LabelWidth="150"></FieldDefaults>
<Items>
<ext:TextField ID="NomTextField" runat="server" AllowBlank="false" IndicatorIcon="BulletRed" MsgTarget="Side" InputWidth="250" MaxLength="50" />
<extuc:RefSelectBox ID="PaysLbxRef" runat="server" LabelWidth="150" AllowBlank="false" IndicatorIcon="BulletRed">
<ListConfig Width="100" />
</extuc:RefSelectBox>
...
this control is added to the tab nested in another tab.
The list width of control is 100%, not the 100px:
7278
7279
Why?
Well, the tab panel in which the web control is added, have layout set to 'fit', but FormPanel in the web control have layout 'form', and even if I change the tab panel's layout to 'form' - the input width will still be 100%, not 100px.
Functionality was copied from the old web control, however...
using Ext.Net;
using RdC.Resources;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Web.UI;
namespace RdC.Front.ServerControls
{
[ToolboxData("<{0}:RefSelectBox runat=server></{0}:RefSelectBox>")]
public class RefSelectBox : SelectBox
{
public Object DataSource { get; set; }
public int? SelectedValue
{
get
{
int res;
if (this.SelectedItem != null && int.TryParse(this.SelectedItem.Value, out res))
{
return res;
}
else {
return null;
}
}
set
{
this.Select(value.ToString());
}
}
public RefSelectBox()
{
this.ListConfig = new BoundList
{
Width = 100
};
this.IndicatorTip = ResourcesManager.GetLabel("RefLbx_IndicatorTip");
this.EmptyText = ResourcesManager.GetLabel("RefLbx_EmptyText");
}
protected override void OnInit(System.EventArgs e)
{
base.OnInit(e);
}
public override void DataBind()
{
if (DataSource != null)
{
Type l_sourceType = DataSource.GetType();
if (l_sourceType.IsGenericType && l_sourceType.GetGenericTypeDefinition() == typeof(List<>))
{
IList l_list = DataSource as IList;
if (l_list != null)
{
foreach (object l_object in l_list)
{
Type l_type = l_object.GetType();
PropertyInfo l_idProp = l_type.GetProperty("Id");
PropertyInfo l_labelleProp = l_type.GetProperty("Libelle");
object l_idValue = l_idProp.GetValue(l_object, null);
object l_labelleValue = l_labelleProp.GetValue(l_object, null);
this.Items.Add(new ListItem
{
Text = l_labelleValue.ToString(),
Value = l_idValue.ToString()
});
}
}
}
}
}
}
}
and I add this control to some FormPanel, which is inside of web control
<ext:FormPanel runat="server" ID="MaSocieteFormPanel" Layout="FormLayout" AutoDoLayout="true" Border="false">
<FieldDefaults LabelWidth="150"></FieldDefaults>
<Items>
<ext:TextField ID="NomTextField" runat="server" AllowBlank="false" IndicatorIcon="BulletRed" MsgTarget="Side" InputWidth="250" MaxLength="50" />
<extuc:RefSelectBox ID="PaysLbxRef" runat="server" LabelWidth="150" AllowBlank="false" IndicatorIcon="BulletRed">
<ListConfig Width="100" />
</extuc:RefSelectBox>
...
this control is added to the tab nested in another tab.
The list width of control is 100%, not the 100px:
7278
7279
Why?
Well, the tab panel in which the web control is added, have layout set to 'fit', but FormPanel in the web control have layout 'form', and even if I change the tab panel's layout to 'form' - the input width will still be 100%, not 100px.