Accessing DropDownList info and values that aren't known until runtime?

G

Guest

This is a crosspost from a less-frequented (but more focused) asp.net group;
I didn't receive an answer that worked. I'd like to get this form
functional. Could someone help on what's probably a simple syntax issue?
I've attempted my due diligence with the usual books and references...but
I'm new to ASP.NET. Question follows:

The Code Project has a nice article on making a "self configuring form
mailer web control." Basically, you apply this control to any form with
ASP.NET textbox server controls on it and it turns the form into something
that's automatically mailed out to an e-mail you specify. Read all about it
here:
http://www.codeproject.com/aspnet/SelfConfigFormMailer.asp

The code works great for textboxes. The author of the article leaves it as
"an exercise for the reader" to configure the program for other types of
controls. The relevant section of code reads as follows:

{
if (control is TextBox)
{
TextBox textBox = (TextBox)control;
if (textBox.Text.Length > 0)
{
if (textBox.ID.ToLower().EndsWith("subject"))
{
subject = textBox.Text; // subject is added as a mail header later
in the code
}
else if (textBox.ID.ToLower().EndsWith("emailaddress"))
{
replyTo = textBox.Text; // add a reply-to header, and
// append the to the text of the message
messageText.Append(mailTemplate.getTemplateText(textBox.ID,
textBox.Text));
}
else
{ // general case, just append to the email body
messageText.Append(mailTemplate.getTemplateText(textBox.ID,
textBox.Text));
}
}
}
// >>> add more types of controls within else if clauses here <<<
}

So what you have going on is the script generates an e-mail string at
runtime using the IDs and Text that are specified by the form developer.

I want the script to work with DropDownLists. I can't figure out how to make
it access the values of the selected listitems. Most of the dropdown scripts
I've seen around the net presume that the name of the parent control
(DropDownList) is specified prior to runtime, but wiring this information in
defeats the point of this generic script.

I've tried a +lot+ of variations, e.g.:
messageText.Append(mailTemplate.getTemplateText(DropDownList.ID.Selecteditem
..Value, DropDownList.ID.Selecteditem.Text))

No joy so far. Can someone help out with what's probably an easy question?

Thanks,

Ken Fine
 
L

Lowell Heddings

if (control is TextBox)
{
TextBox textBox = (TextBox)control;
if (textBox.Text.Length > 0)

I imagine you would do something like this:

if (control is DropDownList)
{
DropDownList dList = (DropDownList)control;
if(dList.Selectedindex > 0)


etc etc etc

Lowell
 

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