当选中复选框时,gridview值来自Excel工作表我希望在单击按钮时将这些行显示到另一个gridview中
protected void Button1_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[5] { new DataColumn("Name of the Chemical "), new DataColumn("Grade"), new DataColumn("Quantity"), new DataColumn("Price in"), new DataColumn("Total") });
foreach (GridViewRow row in GridView1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
CheckBox chkSelect = (row.Cells[0].FindControl("chkSelect") as CheckBox);
if (chkSelect.Checked)
{
string name = row.Cells[1].Text;
string grade = row.Cells[2].Text;
// int quantity = Convert.ToInt32((row.Cells[3].FindControl("Quantity") as TextBox));
//Decimal price = Convert.ToInt32(row.Cells[4].Text);
//Decimal price = Convert.ToDecimal(row.Cells[4]);
//Decimal total = Convert.ToDecimal(row.Cells[5]);
// Convert.ToInt32(GridView1.Rows[rowIndex].Cells[0].Text)
//string country = (row.Cells[2].FindControl("lblCountry") as Label).Text;
dt.Rows.Add(name, grade);
}
}
}
GridView2.DataSource = dt;
GridView2.DataBind();
//gvSelected.DataSource = dt;
//gvSelected.DataBind();
}