Click here to Skip to main content
15,905,913 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I tried as follows

i am displaying the selected row data into listbox.

For that i written the code as follows

C#
foreach (GridViewRow row in gvPkgcbndate.SelectedRow)
    {
        lbllist.Items.Add(row.Cells[0].Text.ToString() + " "  +            row.Cells[1].Text.ToString());

    }


how can i do in asp.net using c#.


When i run error as follows

foreach statement cannot operate on variables of type System.Web.UI.WebControls.GridViewRow because System.Web.UI.WebControls.GridViewRow does not contain a public definition for GetEnumerator.

please help me what is the mistake i made.
Posted
Updated 22-Jul-15 20:18pm
v2

1 solution

GridView.SelectedRow Property returns a (single) reference to a GridViewRow object that represents the selected row. That's why it's throwing error when you want apply a loop on it.

Try-
C#
lbllist.Items.Add(gvPkgcbndate.SelectedRow.Cells[0].Text.ToString() + " "  +            gvPkgcbndate.SelectedRow.Cells[1].Text.ToString());


Hope, it helps :)
 
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