public static String BuildPlainTextEmail(Control containerControl)
{
StringBuilder mailBody = new StringBuilder("");
foreach (Control c in containerControl.Controls)
{
try
{
switch (c.GetType().ToString())
{
case "System.Web.UI.WebControls.TextBox":
TextBox tb = (TextBox)c;
mailBody.Append(c.ID.Replace("_", " ") + ": " + tb.Text + "\r\n");
break;
case "System.Web.UI.WebControls.RadioButtonList":
RadioButtonList rbl = (RadioButtonList)c;
mailBody.Append(c.ID.Replace("_", " ") + ": " + rbl.SelectedValue + "\r\n");
break;
case "System.Web.UI.WebControls.CheckBoxList":
CheckBoxList cbl = (CheckBoxList)c;
mailBody.Append(c.ID.Replace("_", " ") + ": ");
Boolean multiple = false;
for (int x = 0; x < cbl.Items.Count; x++)
{
ListItem li = cbl.Items[x];
if (li.Selected)
{
mailBody.Append((multiple ? "," : "") + li.Value);
multiple = true;
}
}
mailBody.Append("\r\n");
break;
case "System.Web.UI.WebControls.DropDownList":
DropDownList ddl = (DropDownList)c;
mailBody.Append(c.ID.Replace("_", " ") + ": " + ddl.SelectedValue + "\r\n");
break;
case "System.Web.UI.WebControls.ListBox":
ListBox lb = (ListBox)c;
mailBody.Append(c.ID.Replace("_", " ") + ": ");
Boolean multiple2 = false;
for (int x = 0; x < lb.Items.Count; x++)
{
ListItem li = lb.Items[x];
if (li.Selected)
{
mailBody.Append((multiple2 ? "," : "") + li.Value);
multiple2 = true;
}
}
mailBody.Append("\r\n");
break;
case "System.Web.UI.WebControls.HiddenField":
HiddenField hf = (HiddenField)c;
mailBody.Append(c.ID.Replace("_", " ") + ": " + hf.Value + "\r\n");
break;
}
}
catch
{ }
}
return mailBody.ToString();
}