please help me with a Dropdown selectindexchange event into a custom control

K

KMILO

Hello,

Im inserting a dropdownlist into a custom control, I fills it up, change the autopostback property to true, and finally assign the handler to do this event into the control, but in runtime I change the items and nothing happends, any ideas about how to do that correctly, what Im missing?

Thanks in advance.

KMILO.

ps: heres the code:

//setting up the control
private DropDownList MonthsDropDown()
{
foreach (string MonthName in DateTimeFormatInfo.CurrentInfo.MonthNames)
{
if (MonthName != String.Empty)
{
ddlMonths.Items.Add(MonthName);
}
}
ddlMonths.Items.FindByValue(DateTime.Now.ToString("MMMM")).Selected = true;
return ddlMonths;
}

//assign the control to the htmltextwriter and the selectindexchange
protected override void Render(HtmlTextWriter html)
{

_dtSource = null;
if (this.DataSource != null && this.DayField != null)
{
if (this.DataSource is DataTable)
_dtSource = (DataTable) this.DataSource;
if (this.DataSource is DataSet)
{
DataSet ds = (DataSet) this.DataSource;
if (this.DataMember == null || this.DataMember == "")
_dtSource = ds.Tables[0];
else
_dtSource = ds.Tables[this.DataMember];
}
if (_dtSource == null)
throw new Exception("Error finding the DataSource. Please check " +
" the DataSource and DataMember properties.");
}
if (ShowMonthsInDrop)
{
this.ShowTitle = false;
ddlMonths.AutoPostBack = true;
ddlMonths.SelectedIndexChanged +=new EventHandler(ddlMonths_SelectedIndexChanged);
this.MonthsDropDown().RenderControl(html);
}
base.Render(html);
}
 
A

andrew

think you need to look into bubbling an event out. or you can always
create a public event in you control and then when the drop downlist
event fires you raise an event in your control. =/

andrew
Hello,

Im inserting a dropdownlist into a custom control, I fills it up, change the autopostback property to true, and finally assign the handler to do this event into the control, but in runtime I change the items and nothing happends, any ideas about how to do that correctly, what Im missing?

Thanks in advance.

KMILO.

ps: heres the code:

//setting up the control
private DropDownList MonthsDropDown()
{
foreach (string MonthName in DateTimeFormatInfo.CurrentInfo.MonthNames)
{
if (MonthName != String.Empty)
{
ddlMonths.Items.Add(MonthName);
}
}
ddlMonths.Items.FindByValue(DateTime.Now.ToString("MMMM")).Selected = true;
return ddlMonths;
}

//assign the control to the htmltextwriter and the selectindexchange
protected override void Render(HtmlTextWriter html)
{

_dtSource = null;
if (this.DataSource != null && this.DayField != null)
{
if (this.DataSource is DataTable)
_dtSource = (DataTable) this.DataSource;
if (this.DataSource is DataSet)
{
DataSet ds = (DataSet) this.DataSource;
if (this.DataMember == null || this.DataMember == "")
_dtSource = ds.Tables[0];
else
_dtSource = ds.Tables[this.DataMember];
}
if (_dtSource == null)
throw new Exception("Error finding the DataSource. Please check " +
" the DataSource and DataMember properties.");
}
if (ShowMonthsInDrop)
{
this.ShowTitle = false;
ddlMonths.AutoPostBack = true;
ddlMonths.SelectedIndexChanged +=new EventHandler(ddlMonths_SelectedIndexChanged);
this.MonthsDropDown().RenderControl(html);
}
base.Render(html);
}
------=_NextPart_000_0006_01C6D0ED.EE679470
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-Google-AttachSize: 7185

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2963" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=Arial size=2>Hello,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Im inserting a dropdownlist into a custom control,
I fills it up, change the autopostback property to true, and finally assign the
handler to do this event into the control, but in runtime I change the items and
nothing happends, any ideas about how to do that correctly, what Im missing?
</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Thanks in advance.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>KMILO.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>ps: heres the code:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>//setting up the control</FONT></DIV><FONT
face=Arial size=2><FONT color=#0000ff size=2>
<DIV><FONT color=#000000>private</FONT></FONT><FONT size=2> DropDownList
MonthsDropDown()</DIV>
<DIV>{</DIV>
<DIV></FONT><FONT color=#0000ff size=2>foreach</FONT><FONT size=2> (</FONT><FONT
color=#0000ff size=2>string</FONT><FONT size=2> MonthName </FONT><FONT
color=#0000ff size=2>in</FONT><FONT size=2>
DateTimeFormatInfo.CurrentInfo.MonthNames)</DIV>
<DIV>{</DIV>
<DIV></FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2> (MonthName !=
String.Empty)</DIV>
<DIV>{</DIV>
<DIV>ddlMonths.Items.Add(MonthName);</DIV>
<DIV>}</DIV>
<DIV>}</DIV>
<DIV>ddlMonths.Items.FindByValue(DateTime.Now.ToString(</FONT><FONT
color=#800000 size=2>"MMMM"</FONT><FONT size=2>)).Selected = </FONT><FONT
color=#0000ff size=2>true</FONT><FONT size=2>; </DIV>
<DIV></FONT><FONT color=#0000ff size=2>return</FONT><FONT size=2>
ddlMonths;</DIV>
<DIV>}</DIV></FONT></FONT>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>//assign the control to the htmltextwriter and the
selectindexchange </FONT></DIV><FONT color=#0000ff size=2>
<DIV><FONT face=Arial color=#000000>protected</FONT></FONT><FONT
face=Arial><FONT size=2> </FONT><FONT size=2>override</FONT><FONT size=2>
</FONT><FONT size=2>void</FONT></FONT><FONT size=2><FONT face=Arial>
Render(HtmlTextWriter html)</FONT></DIV>
<DIV><FONT face=Arial>{</FONT></DIV>
<DIV><FONT face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial>_dtSource = </FONT></FONT><FONT face=Arial color=#0000ff
size=2>null</FONT><FONT size=2><FONT face=Arial>;</FONT> </DIV>
<DIV></FONT><FONT face=Arial><FONT color=#0000ff size=2>if</FONT><FONT size=2>
(</FONT><FONT color=#0000ff size=2>this</FONT><FONT size=2>.DataSource !=
</FONT><FONT color=#0000ff size=2>null</FONT><FONT size=2> &amp;&amp;
</FONT><FONT color=#0000ff size=2>this</FONT><FONT size=2>.DayField !=
</FONT><FONT color=#0000ff size=2>null</FONT></FONT><FONT size=2><FONT
face=Arial>)</FONT> </DIV>
<DIV><FONT face=Arial>{</FONT></DIV>
<DIV></FONT><FONT face=Arial><FONT color=#0000ff size=2>if</FONT><FONT size=2>
(</FONT><FONT color=#0000ff size=2>this</FONT><FONT size=2>.DataSource
</FONT><FONT color=#0000ff size=2>is</FONT></FONT><FONT size=2><FONT face=Arial>
DataTable)</FONT> </DIV>
<DIV><FONT face=Arial>_dtSource = (DataTable) </FONT></FONT><FONT face=Arial
color=#0000ff size=2>this</FONT><FONT size=2><FONT
face=Arial>.DataSource;</FONT> </DIV>
<DIV></FONT><FONT face=Arial><FONT color=#0000ff size=2>if</FONT><FONT size=2>
(</FONT><FONT color=#0000ff size=2>this</FONT><FONT size=2>.DataSource
</FONT><FONT color=#0000ff size=2>is</FONT></FONT><FONT size=2><FONT face=Arial>
DataSet)</FONT></DIV>
<DIV><FONT face=Arial>{</FONT></DIV>
<DIV><FONT face=Arial>DataSet ds = (DataSet) </FONT></FONT><FONT face=Arial
color=#0000ff size=2>this</FONT><FONT size=2><FONT
face=Arial>.DataSource;</FONT></DIV>
<DIV></FONT><FONT face=Arial><FONT color=#0000ff size=2>if</FONT><FONT size=2>
(</FONT><FONT color=#0000ff size=2>this</FONT><FONT size=2>.DataMember ==
</FONT><FONT color=#0000ff size=2>null</FONT><FONT size=2> || </FONT><FONT
color=#0000ff size=2>this</FONT><FONT size=2>.DataMember == </FONT><FONT
color=#800000 size=2>""</FONT></FONT><FONT size=2><FONT
face=Arial>)</FONT></DIV>
<DIV><FONT face=Arial>_dtSource = ds.Tables[0];</FONT></DIV>
<DIV></FONT><FONT color=#0000ff size=2><FONT
face=Arial>else</FONT></DIV></FONT><FONT size=2>
<DIV><FONT face=Arial>_dtSource = ds.Tables[</FONT></FONT><FONT face=Arial
color=#0000ff size=2>this</FONT><FONT size=2><FONT
face=Arial>.DataMember];</FONT> </DIV>
<DIV><FONT face=Arial>}</FONT></DIV>
<DIV></FONT><FONT face=Arial><FONT color=#0000ff size=2>if</FONT><FONT size=2>
(_dtSource == </FONT><FONT color=#0000ff size=2>null</FONT></FONT><FONT
size=2><FONT face=Arial>)</FONT></DIV>
<DIV></FONT><FONT face=Arial><FONT color=#0000ff size=2>throw</FONT><FONT
size=2> </FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2>
Exception(</FONT><FONT color=#800000 size=2>"Error finding the DataSource.
Please check "</FONT></FONT><FONT size=2><FONT face=Arial> +</FONT></DIV>
<DIV></FONT><FONT face=Arial color=#800000 size=2>" the DataSource and
DataMember properties."</FONT><FONT size=2><FONT face=Arial>);</FONT> </DIV>
<DIV><FONT face=Arial>}</FONT> </DIV>
<DIV></FONT><FONT face=Arial color=#0000ff size=2>if</FONT><FONT size=2><FONT
face=Arial> (ShowMonthsInDrop)</FONT></DIV>
<DIV><FONT face=Arial>{</FONT></DIV>
<DIV></FONT><FONT face=Arial><FONT color=#0000ff size=2>this</FONT><FONT
size=2>.ShowTitle = </FONT><FONT color=#0000ff size=2>false</FONT></FONT><FONT
size=2><FONT face=Arial>;</FONT></DIV>
<DIV><FONT face=Arial>ddlMonths.AutoPostBack = </FONT></FONT><FONT face=Arial
color=#0000ff size=2>true</FONT><FONT size=2><FONT face=Arial>;</FONT></DIV>
<DIV><FONT face=Arial>ddlMonths.SelectedIndexChanged +=</FONT></FONT><FONT
face=Arial color=#0000ff size=2>new</FONT><FONT size=2><FONT face=Arial>
EventHandler(ddlMonths_SelectedIndexChanged);</FONT></DIV>
<DIV></FONT><FONT face=Arial color=#0000ff size=2>this</FONT><FONT size=2><FONT
face=Arial>.MonthsDropDown().RenderControl(html);</FONT> </DIV>
<DIV><FONT face=Arial>}</FONT></DIV>
<DIV></FONT><FONT face=Arial color=#0000ff size=2>base</FONT><FONT size=2><FONT
face=Arial>.Render(html);</FONT></DIV>
<DIV><FONT face=Arial>}</FONT> </DIV></FONT></BODY></HTML>

------=_NextPart_000_0006_01C6D0ED.EE679470--
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top