Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi i need to make a server control that inherits all the behaviours of the drop down control. no customization rightnow what so ever. i just need to be able to use all of its properties like datasource and datatextfield.

but somehow it is not working. can someone please help?

this is the code for the dropdown server control
C#
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(); 
        } 
                
      
    } 
}




C#
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 
            { 
                 
            } 
             
        } 
 
        
       
 
 
      } 
}
Posted
Comments
ZurdoDev 15-Mar-12 8:06am    
What does "not working" mean? What is it doing?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900