Hi posted a problem about dynamic tables but realize i was tackling a giant without learning how to punch first. I just realized my other more simpler controls are not able to save view state also. What i want is simple. I just want to have a custom dropdown
list that inherits everything the dropdown list have. No customization yet whatsover. Tried to use the code but its not loading the items to the dropdownlist...please help
heres the code for both server control and webform. I checked the datatable it has items in it so its not a problem with the data source. Anyone knows whats wrong with it?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace SFAHPOI
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:NpaxDropDown runat=server></{0}:NpaxDropDown>")]
public class NpaxDropDown : DropDownList, IPostBackDataHandler
{
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public string Text
{
get
{
String s = this.Text;
return ((s == null) ? String.Empty : s);
}
set
{
this.Text = value;
EnsureChildControls();
}
}
[Bindable(true)]
[Category("DataBind")]
[DefaultValue("")]
[Localizable(true)]
public DataTable DataSource
{
get
{
DataTable s = (DataTable)ViewState["DataSource"];
return ((s == null) ? new DataTable(): s);
}
set
{
ViewState["DataSource"] = value;
EnsureChildControls();
}
}
[Bindable(true)]
[Category("DataBind")]
[DefaultValue("")]
[Localizable(true)]
public string DataValueField
{
get
{
String s = (string)ViewState["DataValueField"];
if (s == null)
{
return String.Empty;
}
else
{
return s;
}
}
set
{
ViewState["DataValueField"]=value;
EnsureChildControls();
}
}
[Bindable(true)]
[Category("DataBind")]
[DefaultValue("")]
[Localizable(true)]
public string DataTextField
{
get
{
String s = (string)ViewState["DataTextField"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["DataValueField"] = value;
EnsureChildControls();
}
}
protected override void CreateChildControls()
{
this.DataTextField = DataTextField;
this.DataValueField = DataValueField;
this.DataSource = DataSource;
base.CreateChildControls();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SFAHPOI;
using System.Data;
using HpoiBL;
using DevExpress.XtraCharts.Web;
namespace HPOI_SFA
{
public partial class WebForm4 : System.Web.UI.Page
{
string[] usernames= new string[5];
int s;
ScreenMasterBL SM;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
NpaxDropDown1.DataSource = SM.GetScreens();
NpaxDropDown1.DataValueField = "ScreenID";
NpaxDropDown1.DataTextField = "ScreenName";
NpaxDropDown1.DataBind();
}
else
{
}
}
}
}
mbavila
Member
66 Points
56 Posts
Custom DropDown List Server Control
Mar 14, 2012 09:21 AM|LINK
Hi posted a problem about dynamic tables but realize i was tackling a giant without learning how to punch first. I just realized my other more simpler controls are not able to save view state also. What i want is simple. I just want to have a custom dropdown list that inherits everything the dropdown list have. No customization yet whatsover. Tried to use the code but its not loading the items to the dropdownlist...please help
heres the code for both server control and webform. I checked the datatable it has items in it so its not a problem with the data source. Anyone knows whats wrong with it?
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; namespace SFAHPOI { [DefaultProperty("Text")] [ToolboxData("<{0}:NpaxDropDown runat=server></{0}:NpaxDropDown>")] public class NpaxDropDown : DropDownList, IPostBackDataHandler { [Bindable(true)] [Category("Appearance")] [DefaultValue("")] [Localizable(true)] public string Text { get { String s = this.Text; return ((s == null) ? String.Empty : s); } set { this.Text = value; EnsureChildControls(); } } [Bindable(true)] [Category("DataBind")] [DefaultValue("")] [Localizable(true)] public DataTable DataSource { get { DataTable s = (DataTable)ViewState["DataSource"]; return ((s == null) ? new DataTable(): s); } set { ViewState["DataSource"] = value; EnsureChildControls(); } } [Bindable(true)] [Category("DataBind")] [DefaultValue("")] [Localizable(true)] public string DataValueField { get { String s = (string)ViewState["DataValueField"]; if (s == null) { return String.Empty; } else { return s; } } set { ViewState["DataValueField"]=value; EnsureChildControls(); } } [Bindable(true)] [Category("DataBind")] [DefaultValue("")] [Localizable(true)] public string DataTextField { get { String s = (string)ViewState["DataTextField"]; return ((s == null) ? String.Empty : s); } set { ViewState["DataValueField"] = value; EnsureChildControls(); } } protected override void CreateChildControls() { this.DataTextField = DataTextField; this.DataValueField = DataValueField; this.DataSource = DataSource; base.CreateChildControls(); } } }using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using SFAHPOI; using System.Data; using HpoiBL; using DevExpress.XtraCharts.Web; namespace HPOI_SFA { public partial class WebForm4 : System.Web.UI.Page { string[] usernames= new string[5]; int s; ScreenMasterBL SM; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { NpaxDropDown1.DataSource = SM.GetScreens(); NpaxDropDown1.DataValueField = "ScreenID"; NpaxDropDown1.DataTextField = "ScreenName"; NpaxDropDown1.DataBind(); } else { } } } }