1

I have an page that list rows from my DB table, with User Name and an CheckBox. I need an function that send email to User when CheckBox.checked is true, but don't show Email in my page. I have these mothods:

public class ListRequest
{
    public string UserName { get; set; }
    public string Email { get; set; }
}

public List<ListRequest> PreencheValores(SqlDataReader reader)
{
    var lista = new List<ListRequest>();
    while (reader.Read())
    {
        var listRequest = new ListRequest();
        listRequest.UserName = reader["User"].ToString();
        listRequest.Email = reader["Email"].ToString();
        lista.Add(listRequest);
    }
    return lista;
}

public List<ListRequest> ConsultarRequest()
{
    var lstRetorno = new List<ListRequest>();
    using (objConexao = new SqlConnection(strStringConexao))
    {
        using (objCommand = new SqlCommand(strSelectPorID, objConexao))
        {
            try
            {
                objConexao.Open();
                objCommand.Parameters.AddWithValue("@UserName", dm3);

                var objDataReader = objCommand.ExecuteReader();
                if (objDataReader.HasRows)
                    lstRetorno = PreencheValores(objDataReader);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                objConexao.Close();
            }
        }
    }
    return lstRetorno;
}

How I can make foreach for this?? I need get all string Email to this list but don't show Email in my page. now I use foreach (GridViewRow row in GridView.Rows) to get name when CheckBox.cheked is true. I'm clear in question? Tks!

4
  • 2
    so it looks like you have code to obtain the email address/es for a user-name; can't you just call that method, and iterate over the returned list? where are you stuck? Commented Jul 10, 2013 at 13:52
  • 1
    One option is to insert a hidden field with the email value, and then you get the hidden field control in the same way you did with the checkbox. If you want to hide the email from hidden fields, consider cache the bound collection and insert an identifier into the hidden field. Commented Jul 10, 2013 at 13:53
  • @MarcGravell I have an method to event Send (an Button in my page). in this method I need an foreach to get each email to User Name when is Checked. How I said, I make an foreach (GridViewRow row in GridView.Rows), but it not get Email because Email not shows in my GridView. How I make an foreach to my list? Commented Jul 10, 2013 at 13:58
  • @gustavodidomenico Tks for your answer! I created an asp:HiddenField to Email and works correctly! Commented Jul 10, 2013 at 14:12

1 Answer 1

1

If you want to do something with each row in objDataReader, use

While objDataReader.Read()
    'do something
End While
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.