Custom Server Control Property

J

Joe

I wrote a simple server control that inherits from the DropDownList
control. I will be using the control in an aspx page and want to
access it in a repeater. I have created a public property called
DefaultValue. For some reason, the property is never set from within
my aspx page. It just gets ignored. Does anyone know why?

Here is how it looks in my aspx:
--------------------------------------------------------

<frmcontrol:controltypedropdown DefaultValue="5"
id="Controltypedropdown1" runat="server"/>

----------------------------------------------------------
Below is my control code.
-----------------------------------------------------------

namespace blah.Controls
{

/// <summary>
/// A server control to display the dropdown of Control Types. Will
be
/// displayed programatically in a repeater.
/// </summary>
public class ControlTypeDropDown :
System.Web.UI.WebControls.DropDownList
{
private DataTable dt;
private ListItem[] coll;

private string defaultValue="0";
public string DefaultValue
{
get{return defaultValue;}
set{defaultValue=value;}
}

public ControlTypeDropDown() : base()
{
lock(this)
{
if(HttpContext.Current.Application["ControlTypeDropDown"]==null)
{
Survey s = new Survey();
dt = s.GetFormControls();


coll = new ListItem[dt.Rows.Count+1];
coll[0] = new ListItem("", "0");
for(int i=0;i<dt.Rows.Count;i++)
{
coll[i+1] = new ListItem(Convert.ToString(dt.Rows["type"]),
Convert.ToString(dt.Rows["controlTypeId"]));
}

HttpContext.Current.Application.Add("ControlTypeDropDown", coll);
}
else
{
coll = (ListItem[])HttpContext.Current.Application["ControlTypeDropDown"];
}

this.Items.AddRange(coll);
this.Items.FindByValue(DefaultValue).Selected=true;
}
}




}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top