I am creating a program that holds customers details and sends them an email alerting them of special offers. I am having trouble when I export the email data as I want to store it in the sendto.text
field separating each address with a comma, How can I get the data from each row of the datagrid
and can it be stored and separated with a comma in a textfield
?.
Hope this makes sense. Thanks
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
sendto.text = dataGridView1.Rows[i].Cells[3].Value.ToString());
}
Like this?:
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
sendto.text += dataGridView1.Rows[i].Cells[3].Value.ToString() + (i < (dataGridView1.Rows.Count-1) ? "," : "");
}
you can add comma from second emailid onwards.
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if(i>0)
sendto.text +=","+ dataGridView1.Rows[i].Cells[3].Value.ToString());
else
sendto.text = dataGridView1.Rows[i].Cells[3].Value.ToString());
}
StringBuilder stremail = new StringBuilder();
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
stremail.Append(dataGridView1.Rows[i].Cells[3].Value.ToString() + ",");
}
int stringWithoutLastComma = --stremail.Length;
sendto.text = stremail.ToString(0,stringWithoutLastComma);
You can:
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
sendto.text += string.Format("{0},", dataGridView1.Rows[i].Cells[3].Value.ToString());
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.