Click here to Skip to main content
15,903,201 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
foreach (GridViewRow gvRowAssigment in GridViewAllAssigments.Rows)
            {
var emp_assig_ref = new EMPLOYEES_ASSIGMENT_REFERENCE();
                emp_assig_ref.reference_name = gvRowAssigment.Cells[0].Text;

}


This is not working i get no value in the column , i have been googling al they

C#
emp_assig_ref.reference_name = gvRowAssigment.Cells[0].Value.ToString();


Like this many site says , but my intellisense cannot find value, i have find out were to find value now but when i change the foreach to " foreach (DataGridViewRow gvRowAssigment in GridviewAllassigment.Rows)

i get this error:
Unable to cast object of type 'System.Web.UI.WebControls.GridViewRow' to type 'System.Windows.Forms.DataGridViewRow'.
Posted
Updated 23-Mar-13 8:59am
v2

1 solution

Hi,
The error is telling you that you cannot cast System.Web.UI.WebControls.GridViewRow to System.Windows.Forms.DataGridViewRow.
In simple words casting green apples to red apples, although they are apple, but different in some context.
use your foreach loop to use System.Web.UI.WebControls.GridViewRow as your GridViewAllAssigments is System.Web.UI.WebControls.GridView.

C#
foreach(System.Web.UI.WebControls.GridViewRow gvRowAssigment in GridViewAllAssigments.Rows)


I hope this helps.

Regards
Jegan
 
Share this answer
 

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