Click here to Skip to main content
15,886,693 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have a grid view in which there are 6 columns ,the sixth clumn contains email addresses, i want that only the sixth column is put into an array and then i send mail on that using the array


Please guide me in this regard or if any one has a code of it then give me

Thanks in Advance
Posted
Updated 5-Jun-11 19:55pm
v2

What do you mean out into an array?

It's not the GridView you need to look at but rather the DataSource that is bound to it.

List<string> emails = new List<string>();
DataTable dt = (DataTable)grid.DataSource;
foreach(DataRow row in dt.Rows)
{
   emails.Add(row[5]); 
}
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 5-Jun-11 21:11pm    
Good idea about binding, my 5. What if there is no binding?
--SA
[no name] 5-Jun-11 21:40pm    
If there is no data binding then there isn't much point in using a GridView is there?
Sergey Alexandrovich Kryukov 5-Jun-11 23:29pm    
Agree, would be pretty bad idea, but formally the question makes sense. No, I don't think answering it makes sense, I just asked for the completeness.
--SA
Sergey Alexandrovich Kryukov 5-Jun-11 23:30pm    
Another valid question is by Wonde (below). But your general idea about working with data not UI elements is quite right.
--SA
Wonde Tadesse 5-Jun-11 23:11pm    
Good Answer.5+. But, what if the Datasource is list collection ? Generic or ArrayList
Try this

string[] arrEmail=new string[dgvList.Rows.Count];
for (int i = 0; i < dgvList.Rows.Count-1; i++)
{
  arrEmail[i] = dgvList.Rows[i].Cells[5].Value.ToString();                
}
 
Share this answer
 
v4
Comments
dibdab 27-Jan-18 12:44pm    
Any idea why do I get "Value" underlined? saying table cell do not contain definition for Value.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900