User-534664927 posted
Hi All,
I've created custom TemplateField and added new property ControlType which specifies if insert/edit item is textbox ,dropdownlist etc.
However, during constructor call ControlType property is not set yet and always have default value. When ControlType property is already set? (Initialize method is one of them but that's too late)
My code:
<CustomGridView:CCustomGridView runat="server" ID="customGridView" AutoGenerateColumns="false" InsertRowActive="false" DataSourceID="dataSource" DataKeyNames="Id">
<Columns>
<CustomGridView:CustomTemplateField HeaderText="BuySell" ControlType="DropDownList">
</CustomGridView:CustomTemplateField>
// Custom TemplateField:
public class CustomTemplateField : TemplateField
{
public CustomTemplateField() : base()
{
if (ControlType == ControlTypes.DropDownList)
{
EditItemTemplate = new DDLItemTemplate();
InsertItemTemplate = new DDLItemTemplate();
}
ItemTemplate = new ViewItemTemplate();
}
public enum ControlTypes
{
DropDownList,
CheckBox,
TextBox
}
[Category("Behaviour")]
[Description("Control used inside field")]
public ControlTypes ControlType
{
get
{
if (this.ViewState["ControlType"] == null)
return ControlTypes.TextBox;
return (ControlTypes)this.ViewState["ControlType"];
}
set
{
this.ViewState["ControlType"] = value;
}
}
}