人〜
C# を使用して、CompositeDataBoundControl から継承するカスタム グリッドビューを作成しています。以下のように「列」と呼ばれるパブリック プロパティがあります。
private FixedGridColumnCollection _columnCollection = null;
/// <summary>
/// FixedGrid's columns
/// </summary>
[Category("BANANA Framework")]
[Description("Gets or sets FixedGrid's columns")]
[Editor(typeof(FixedGridColumnCollectionEditor), typeof(UITypeEditor))]
[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[ReadOnly(true)]
public FixedGridColumnCollection Columns
{
get
{
if (this._columnCollection == null)
this._columnCollection = new FixedGridColumnCollection();
if (base.IsTrackingViewState)
{
((IStateManager)(this._columnCollection)).TrackViewState();
}
return _columnCollection;
}
}
FixedGridColumnCollection クラスは以下のとおりです。
[TypeConverter(typeof(FixedGridColumnConverter))]
public class FixedGridColumnCollection : StateManagedCollection
{
// Fields
#region Type : FixedGrid's column types
/// <summary>
/// FixedGrid's column types
/// </summary>
private static readonly Type[] _knownTypes = new Type[]
{
typeof(BANANA.Web.Controls.BoundDataField)
, typeof(BANANA.Web.Controls.TextBoxField)
, typeof(BANANA.Web.Controls.HyperLinkField)
, typeof(BANANA.Web.Controls.LinkButtonField)
, typeof(BANANA.Web.Controls.CheckBoxField)
, typeof(BANANA.Web.Controls.DropDownListField)
, typeof(BANANA.Web.Controls.RadioButtonField)
, typeof(BANANA.Web.Controls.DatePickerField)
, typeof(BANANA.Web.Controls.CodeHelperField)
, typeof(BANANA.Web.Controls.TemplateField)
};
#endregion
// Properties
#region BoundFieldBase
public BaseDataField this[int index]
{
get { return (BaseDataField)((IList)this)[index]; }
}
#endregion
#region Type
protected override Type[] GetKnownTypes()
{
return _knownTypes;
}
#endregion
// Methods
#region Add
public int Add(BaseDataField item)
{
return ((IList)this).Add(item);
}
#endregion
#region Remove
public void Remove(BaseDataField item)
{
((IList)this).Remove(item);
}
#endregion
#region SetDirtyObject
protected override void SetDirtyObject(object o)
{
((BaseDataField)o).SetDirty();
}
#endregion
#region CreateKnownType
protected override object CreateKnownType(int index)
{
switch (index)
{
case 0:
return new BANANA.Web.Controls.BoundDataField();
case 1:
return new BANANA.Web.Controls.TextBoxField();
case 2:
return new BANANA.Web.Controls.HyperLinkField();
case 3:
return new BANANA.Web.Controls.LinkButtonField();
case 4:
return new BANANA.Web.Controls.CheckBoxField();
case 5:
return new BANANA.Web.Controls.DropDownListField();
case 6:
return new BANANA.Web.Controls.RadioButtonField();
case 7:
return new BANANA.Web.Controls.DatePickerField();
case 8:
return new BANANA.Web.Controls.CodeHelperField();
case 9:
return new BANANA.Web.Controls.TemplateField();
default:
throw new Exception("Does not support this kind of filed in FixedGrid.");
}
}
#endregion
#region OnValidate
protected override void OnValidate(object o)
{
base.OnValidate(o);
if (!(o is BaseDataField))
throw new ArgumentException("It must be value of BaseDataField.", "value");
}
#endregion
}
列が静的に宣言されている場合、ページで正常に機能します。しかし、列を動的に作成すると、以下のようにポストバックするとすべての列が失われます。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BANANA.Web.Controls.BoundDataField field = null;
BANANA.Web.Controls.TemplateField tField = null;
tField = new BANANA.Web.Controls.TemplateField();
tField.ItemTemplate = new GridViewRadioButtonTemplate("APPSTATUS", _strRadioButtonID);
tField.ID = "APPSTATUS";
tField.Width = 30;
tField.HorizontalAlignment = BANANA.Web.Controls.HorizontalAlignment.Center;
this.FixedGrid1.Columns.Add(tField);
FixedGrid1.DataSource = _dt;
FixedGrid1.DataBind();
}
}
コードの何が問題になっていますか? 誰か手がかりを教えてください。