c#函数为什么被执行了两次

来源:百度知道 编辑:UC知道 时间:2024/06/24 13:25:59
protected void hideModalPopupViaServer_Click(object sender, EventArgs e)
{
string goodsID = "";
for (int i = 0; i < gvProductList.Rows.Count; i++)
{
if (((CheckBox)gvProductList.Rows[i].FindControl("chkSelect")).Checked == true)
{
goodsID = ((Label)gvProductList.Rows[i].FindControl("lblID")).Text;
this.BindProductSelectedData(goodsID);//被执行了两次
}
}
this.programmaticModalPopup.Hide();
}
#endregion

#region 绑定选择的产品信息
private void BindProductSelectedData(string strProductID)
{
Model.GoodsMst modelGoodsMst = bllGoodsMst.GetModel(strProductID);
DataTable dt = ReadGridView();
bool found = false;

for (int i = 0; i < dt.Rows.Count; i++)
{
if (dt.Rows[i]["Good

你是在for循环执行BindProductSelectedData()
肯定会执行多次了。。
你选择了几个产品,就会执行几次。

感觉问题出在这个循环上:
for (int i = 0; i < gvProductList.Rows.Count; i++)

设置断点,运行调试 F11 每个执行步骤看详细一点