I tried my code as follows
I am dsiplaying gridview selected row data into listbox.
In gridview run mode as follows
select (header text) AVailable dates
select (button) 27 may 2015
select(button) 30 may 2015
When i select the above two from the girdview. i want to display two selected rows values t listbox.
protected void gvPkgcbndate_SelectedIndexChanged1(object sender, EventArgs e)
{
foreach (GridViewRow row in gvPkgcbndate.SelectedRow)
{
lbllist.Items.Add(row.Cells[0].Text.ToString() + " " + row.Cells[1].Text.ToString());
}
}
In listbox i want output as follows
27 may 2015
30 may 2015
i tried but show 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'
how to solve my error. please help me.
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Munesh SharmaPosted Jul 24, 2015, 3:17 AM
foreach (DataGridViewRow row in dataGridView1.SelectedRows)
{
listBox1.Items.Add(row.Cells[0].Value.ToString() +" "+row.Cells[1].Value.ToString() +" "+ row.Cells[2].Value.ToString());
}
When we select rows using RowHeader, we get result as below