473,512 Members | 15,089 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DropDown List Custom Control

This one should be a fairly simple one for you guys. I want to create a
small dropDown list (custom control) and when the user selects anyone of the
value, the control should pass back the Selected Value. This is what I did
till now and I do not know how to pass back the selected value .. Please
help

public class DDControl : System.Web.UI.WebControls.WebControl,
IPostBackEventHandler
{
protected override void Render(HtmlTextWriter output)
{
string s1 = "<SELECT NAME=\"pizzasize\">" ;
string s2 = "<OPTION VALUE=\"s\">" ;
string s3 = "small";
string s4 = "<OPTION VALUE=\"m\">" ;
string s5 = " medium" ;
string s6 = "<OPTION VALUE=\"l\">" ;
string s7 = "large" ;
string s8 = "</SELECT>" ;
output.Write(s1+s2+s3+s4+s5+s6+s7+s8) ;
}
public event EventHandler DropDownChange;

public void RaisePostBackEvent(string eventArgument)
{
OnDropDownChange(EventArgs.Empty);
}

protected virtual void OnDropDownChange(EventArgs e)
{
if (DropDownChange != null)
{
DropDownChange(this, e);
}
}

}

Thanks
Steven
Nov 19 '05 #1
2 1536
There's a much better way to do this...you are reinventing too much on the
plumbing...

why not just create a control which inherits from DropDownList and add the 3
list items?

public class DDControl : DropDownList{
protected override void CreateChildControls(){
Items.Add(new ListItem("small", "s"));
Items.Add(new ListItem("medium", "m"));
Items.Add(new ListItem("large", "m"));
base.CreateChildControls ();
}
}

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Steven" <st*****@anonymous.com> wrote in message
news:ez**************@TK2MSFTNGP12.phx.gbl...
This one should be a fairly simple one for you guys. I want to create a
small dropDown list (custom control) and when the user selects anyone of
the value, the control should pass back the Selected Value. This is what I
did till now and I do not know how to pass back the selected value ..
Please help

public class DDControl : System.Web.UI.WebControls.WebControl,
IPostBackEventHandler
{
protected override void Render(HtmlTextWriter output)
{
string s1 = "<SELECT NAME=\"pizzasize\">" ;
string s2 = "<OPTION VALUE=\"s\">" ;
string s3 = "small";
string s4 = "<OPTION VALUE=\"m\">" ;
string s5 = " medium" ;
string s6 = "<OPTION VALUE=\"l\">" ;
string s7 = "large" ;
string s8 = "</SELECT>" ;
output.Write(s1+s2+s3+s4+s5+s6+s7+s8) ;
}
public event EventHandler DropDownChange;

public void RaisePostBackEvent(string eventArgument)
{
OnDropDownChange(EventArgs.Empty);
}

protected virtual void OnDropDownChange(EventArgs e)
{
if (DropDownChange != null)
{
DropDownChange(this, e);
}
}

}

Thanks
Steven

Nov 19 '05 #2
Hello Karl,

Thanks for your reply!

The control I'm creating will contain many child controls like textboxes,
buttons and dropdownlists. I just split my code into small module, where I
just want to create Dropdownlist and raise the postback event. Could you
please explain me on how to do that?

Thanks
Steven

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:uS**************@TK2MSFTNGP15.phx.gbl...
There's a much better way to do this...you are reinventing too much on the
plumbing...

why not just create a control which inherits from DropDownList and add the
3 list items?

public class DDControl : DropDownList{
protected override void CreateChildControls(){
Items.Add(new ListItem("small", "s"));
Items.Add(new ListItem("medium", "m"));
Items.Add(new ListItem("large", "m"));
base.CreateChildControls ();
}
}

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Steven" <st*****@anonymous.com> wrote in message
news:ez**************@TK2MSFTNGP12.phx.gbl...
This one should be a fairly simple one for you guys. I want to create a
small dropDown list (custom control) and when the user selects anyone of
the value, the control should pass back the Selected Value. This is what
I did till now and I do not know how to pass back the selected value ..
Please help

public class DDControl : System.Web.UI.WebControls.WebControl,
IPostBackEventHandler
{
protected override void Render(HtmlTextWriter output)
{
string s1 = "<SELECT NAME=\"pizzasize\">" ;
string s2 = "<OPTION VALUE=\"s\">" ;
string s3 = "small";
string s4 = "<OPTION VALUE=\"m\">" ;
string s5 = " medium" ;
string s6 = "<OPTION VALUE=\"l\">" ;
string s7 = "large" ;
string s8 = "</SELECT>" ;
output.Write(s1+s2+s3+s4+s5+s6+s7+s8) ;
}
public event EventHandler DropDownChange;

public void RaisePostBackEvent(string eventArgument)
{
OnDropDownChange(EventArgs.Empty);
}

protected virtual void OnDropDownChange(EventArgs e)
{
if (DropDownChange != null)
{
DropDownChange(this, e);
}
}

}

Thanks
Steven


Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1252
by: Kay | last post by:
Hello, I have developed a web custom control, I want one of the properties of the control to appear as a dropdown list so the user can select from the list. My question is: how do I define an...
0
1226
by: Kay | last post by:
Hello, I have developed a web custom control, I want one of the properties of the control to appear as a dropdown list so the user can select from the list. My question is: how do I define an...
0
2895
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
0
1336
by: Kay | last post by:
Hello, I have written my own custom control and I want one of its properties to display as a dropdown list when clicked, so the user can select from the list, it would be similar to the asp...
0
1601
by: Kay O'Keeffe | last post by:
Hello, I have written my own custom control and I want one of its properties to display as a dropdown list when clicked, so the user can select from the list, it would be similar to the asp...
0
7252
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7371
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5676
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5077
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1583
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.