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;
}
ASKER