0

I am trying to change the variable:

.ToAddress = ConfigurationManager.AppSettings("RequestEmail")

based on the selected value in the CheckBoxList ListItem. So far it's not working.

Here's the code for that list:

<asp:CheckBoxList runat="server" ID="m_chckbxlstProperties" RepeatDirection="horizontal" RepeatColumns="2" CssClass="checkboxlist">
    <asp:ListItem Value="1"></asp:ListItem>
    <asp:ListItem Value="2"></asp:ListItem>
    <asp:ListItem Value="3"></asp:ListItem>
    <asp:ListItem Value="4"></asp:ListItem>
    <asp:ListItem Value="5"></asp:ListItem>
    <asp:ListItem Value="6"></asp:ListItem>
    <asp:ListItem Value="7"></asp:ListItem>
    <asp:ListItem Value="8"></asp:ListItem>
    <asp:ListItem Value="9"></asp:ListItem>
</asp:CheckBoxList> 

Here is the code behind:

For Each li In m_chckbxlstProperties.Items
  If li.Value = "1" Then
   If li.Selected Then
    .ToAddress = ConfigurationManager.AppSettings("1RequestEmail")
   End If
  Else If li.Value = "2" Then
  If li.Selected Then
    .ToAddress = ConfigurationManager.AppSettings("2RequestEmail")
   End If
  Else If li.Value = "3" Then
  If li.Selected Then
     .ToAddress = ConfigurationManager.AppSettings("3RequestEmail")
    End If    
  Else If li.Value = "4" Then
  If li.Selected Then
     .ToAddress = ConfigurationManager.AppSettings("4RequestEmail")
    End If  
  Else
     .ToAddress = ConfigurationManager.AppSettings("RequestEmail")
    End If
  End If
 Next
3
  • What does .ToAddress belong to? I'm assuming you have a With statement somewhere. Do 1RequestEmail, 2RequestEmail, 3RequestEmail, 4RequestEmail, RequestEmail exist in your web.config? Nov 13, 2013 at 22:21
  • I moved your if li.selected to outside the value checking routine. This code should only be executing once, so why not move it outside? Readability improved.
    – ps2goat
    Nov 13, 2013 at 22:41
  • Yes, the .ToAddress is in my Email.vb file in my app_code and part of the namespace Email. You are correct, all the RequestEmails are in my web.config. The email works fine but when the different emails for list item values were thrown in as a stick in the works it got complicated. Nov 14, 2013 at 15:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.