Click here to Skip to main content
15,908,445 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi hot to get gridview cell value in foreachloop please find me soln...
My code it returns only Header Text not cell value
C#
for (int i = 0; i < dg.Rows.Count; i++)
        {
            strB.AppendLine("<tr>");
           for(int j=0;j<dg.Columns.Count;j++)
            {
                [B]strB.AppendLine("<td align='center' valign='middle'>" +
                                dg.Columns[j].ToString() + "</td>");[/B] //Here i'm getting Header text value instead of cell value
            }
            strB.AppendLine("</tr>");

        }
Posted
Updated 29-Nov-12 20:20pm
v2

Sorry it's not working it's not accepting muktidimension value....Any other soln...
 
Share this answer
 
Update your code as below.

C#
for (int i = 0; i < dg.Rows.Count; i++)
{
   strB.AppendLine("<table><tbody><tr>");
   for(int j=0;j<dg.columns.count;j++)>
   {
      [B]strB.AppendLine("<td align="center" valign="middle">" +
             dg.Rows[i].Cells[j].ToString() + "</td>");[/B] 
   }
   strB.AppendLine("</tr></tbody></table>");
}

Hope this will help you.
 
Share this answer
 
v2

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