Code
/// <summary>
/// 包装单位选择发生变化
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlUnitname_SelectedIndexChanged(object sender, EventArgs e)
{
//选择不同的包装入库
DataSet ds = (DataSet)ViewState["dbMateriels"];
DataTable tmp1dt = ds.Tables[0];
DataTable tardt = tmp1dt.Clone();
for (int i = 0; i < tmp1dt.Rows.Count; i++)
{
for (int j = 0; j < gvMaterialDetail.Rows.Count; j++)
{
if (tmp1dt.Rows[i]["tmpid"].ToString() == gvMaterialDetail.DataKeys[j]["tmpid"].ToString())
{
DropDownList ddl = (DropDownList)gvMaterialDetail.Rows[j].FindControl("ddlUnitname");
Label lbl = (Label)gvMaterialDetail.Rows[j].FindControl("lblUnitname");
DataRow dr = tardt.NewRow();
dr = tmp1dt.Rows[i];
if (ddl.SelectedValue.ToString() != null && ddl.SelectedValue.ToString() != "")
{
dr["unit"] = ddl.SelectedValue.ToString();
}
tardt.Rows.Add(dr.ItemArray);
}
}
}
gvMaterialDetail.DataSource = tardt;
this.gvMaterialDetail.DataKeyNames = new string[] { "unit", "recordid", "tmpid","billleftnumb","numb" };
gvMaterialDetail.DataBind();
}
DataRow dr = tardt.NewRow();
dr = tmp1dt.Rows[i];
if (ddl.SelectedValue.ToString() != null && ddl.SelectedValue.ToString() != "")
{
dr["unit"] = ddl.SelectedValue.ToString();
}
tardt.Rows.Add(dr.ItemArray);
如果tardt.Rows.Add(dr)
就会产生该列已属于另一个表的错误