100分求解 gridview 绑定 刷新问题
功能描述:
同一页面 上部选择Agridview的某些记录行
暂存ArrayList中 并绑定到同一页面中另外一Bgridview 显示出来
同一页面有一个dropdownlist 控制Agridview的显示内容
当dropdownlist 第一次触发事件
Agridview显示出内容 选择其数据条目 在Bgridview 显示出来没问题
但
********************
当dropdownlist 第二次以及以后触发事件Agridview显示出内容 选择其数据条目后
Bgridview 显示的数据条目已替代第一次选择的数据条目
如何解决 使Bgridview 不替代之前的的数据 而是继续累加进去??????????
-------------------------------------------------------------------
附CODE
DAL dal = new DAL(); IList list = new ArrayList(); IList listALL = new ArrayList();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
// Button1.Attributes.Add("onclick", "javascript:return confirm('确认?')");
}
}
protected void DDL_Plant_SelectedIndexChanged(object sender, EventArgs e)
{
BindGrid();
}
protected void Button1_Click(object sender, EventArgs e)
{
//Response.Redirect("Message.aspx?msg=" + HttpUtility.UrlEncode("制定成功!"), false);
for (int i = 0; i < GridView1.Rows.Count; i++)
{
// MacObject d = new MacObject((GridView1.Rows.Count + 1).ToString());
HtmlInputCheckBox checkBox = (HtmlInputCheckBox)GridView1.Rows[i].Cells[0].FindControl("id");
if (checkBox != null && checkBox.Checked)
{
// IList list = new ArrayList();
MacObject d = new MacObject("1");
d.M_ID = GridView1.DataKeys[i].Value.ToString();
d.Mac_Name = GridView1.Rows[i].Cells[1].Text.ToString();
d.Mac_xxName = GridView1.Rows[i].Cells[2].Text.ToString();
d.Mac_UsePosition = GridView1.Rows[i].Cells[3].Text.ToString();
d.Mac_Body = GridView1.Rows[i].Cells[4].Text.ToString();
d.Mac_JCZQ = GridView1.Rows[i].Cells[5].Text.ToString();
d.JCSD_DL = ((CheckBox)GridView1.Rows[i].Cells[6].Controls[1]).Checked;
d.JCSD_TS = ((CheckBox)GridView1.Rows[i].Cells[7].Controls[1]).Checked;
d.JCSD_DJGZ = ((CheckBox)GridView1.Rows[i].Cells[8].Controls[1]).Checked;
d.JCSD_ZD = ((CheckBox)GridView1.Rows[i].Cells[9].Controls[1]).Checked;
d.JCSD_FR = ((CheckBox)GridView1.Rows[i].Cells[10].Controls[1]).Checked;
d.Mac_CKname = GridView1.Rows[i].Cells[11].Text.ToString();
list.Add(d);
GridView2.DataSource = list;
GridView2.DataBind();
}
}
/**
CheckBox b = (CheckBox)row.Cells[6].Controls[1];
d.JCSD_DL = b.Checked;
// d.JCSD_DL = ((CheckBox)row.Cells[6].Controls[1]).Checked;
d.JCSD_TS = Convert.ToBoolean(row.Cells[7].Text.ToString());
d.JCSD_DJGZ = Convert.ToBoolean(row.Cells[8].Text.ToString());
d.JCSD_ZD = Convert.ToBoolean(row.Cells[9].Text.ToString());
d.JCSD_FR = Convert.ToBoolean(row.Cells[10].Text.ToString());
/**
d.Mac_Name = ((TextBox)row.FindControl("设备名称")).Text;
d.Mac_xxName = ((TextBox)row.FindControl("设备详细名称或编号")).Text;
d.Mac_UsePosition = ((TextBox)row.FindControl("使用地点")).Text;
d.Mac_Body = ((TextBox)row.FindControl("点检部位")).Text;
d.Mac_JCZQ = ((DropDownList)row.FindControl("检测周期")).SelectedItem.Text;
d.JCSD_FR = ((CheckBox)row.FindControl("发热")).Checked;
d.JCSD_ZD = ((CheckBox)row.FindControl("振动")).Checked;
d.JCSD_DJGZ = ((CheckBox)row.FindControl("电机故障")).Checked;
d.JCSD_TS = ((CheckBox)row.FindControl("探伤")).Checked;
d.JCSD_DL = ((CheckBox)row.FindControl("电缆")).Checked;
* **/
}
void BindGrid()
{
string ddlselect = DDL_Plant.SelectedItem.Text.ToString().Replace(" ", "");
string sql = "select * from T_MacUpInfo_Finished where replace(SourceCK,' ','') = '" + ddlselect + "'";//
DataTable dt = dal.FillDataTable(sql, null);
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
Label2.Visible = false;
GridView1.Visible = true; Button1.Enabled = true;
}
else
{
GridView1.Visible = false; Button1.Enabled = false;
Label2.Visible = true; Label2.Text = ",请核查!";
}
}