Avatar of dodgerfan
dodgerfanFlag for United States of America

asked on 

Build a string of emails from a gridview

I have a gridview in ASP.Net that display data from a database table. One of the fields is an email address. I am using stringbuilder to create a string of all of the emails to include elsewhere in an email message. I'm trying to get it formatted right. Right now it creates the string but there are extra spaces when I try to add a ; to the end of each email.

It comes out this way: test@email1 ; test2@email2 ; test3@email3 ;
I'd like I to appear this way: test@email1; test2@email2; test3@email3

My code looks like this right now:

public void getdata()
{
string connectionString = ConfigurationManager.ConnectionStrings["myConn"].ConnectionString;

using (SqlConnection sqCon = new SqlConnection(connectionString))
{
sqCon.Open();
using (SqlCommand cmd = new SqlCommand("SELECT * FROM Users", sqCon))
{
SqlDataReader reader = cmd.ExecuteReader();
gvNames.DataSource = reader;
gvNames.DataBind();
}}}

public void WriteString()
{
        StringBuilder str = new StringBuilder();
        foreach (GridViewRow row in gvNames.Rows)
        {
          str.AppendLine(row.Cells[0].Text).Append(";");
        }
        string strEmails = str.ToString();
        lblString.text = strEmails;
}
ASP.NETC#

Avatar of undefined
Last Comment
dodgerfan
ASKER CERTIFIED SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of dodgerfan
dodgerfan
Flag of United States of America image

ASKER

Thank you.
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo