0

这不起作用:

var originalFinalShowsTable = Session["finalShowsTable"] as DataTable;

DataTable finalShowsTable = new DataTable();

finalShowsTable = originalFinalShowsTable.Clone();

foreach (GridViewRow gvr in gvShows.Rows)
{
    if (gvr.RowType == DataControlRowType.DataRow)
    {
         if (((CheckBox) gvr.FindControl("cbSelect")).Checked)
         {
               finalShowsTable.Rows.Add(gvr);
         }
     }
}

它所做的是将文本"System.Web.UI.WebControls.GridViewRow"放入数据表的第一列。

4

1 回答 1

2

尝试这个 :

DataTable finalShowsTable = new DataTable();

    finalShowsTable = originalFinalShowsTable.Clone();

    foreach (GridViewRow gvr in gvShows.Rows)
    {
        if (gvr.RowType == DataControlRowType.DataRow)
        {
             if (((CheckBox) gvr.FindControl("cbSelect")).Checked)
             {
                    DataRow dr= finalShowsTable.NewRow();
                     for (int i = 0; i < gvr.Cells.Count - 1; i++)
                     {
                         dr[i] = row.Cells[i].Text;
                     }

                     finalShowsTable.Rows.Add(dr);
             }
         }
    }
于 2013-07-08T18:05:40.587 回答