protected void LinkButtonUpdate_Click(object sender, EventArgs e)
{
int nCount = GridView1.Rows.Count;
int nSelectNum = 0;
for (int i = 0; i < nCount; i++)
{
CheckBox CheckBox1 = GridView1.Rows[i].Cells[0].FindControl("CheckBox1") as CheckBox;
if (CheckBox1.Checked)
{
nSelectNum++;
}
}
if (nSelectNum > 1)
{
Response.Write("<script>alert('不能选择多个记录进行修改!')</script>");
}
else
{
nCount = GridView1.Rows.Count;
for (int i = 0; i < nCount; i++)
{
CheckBox CheckBox1 = GridView1.Rows[i].Cells[0].FindControl("CheckBox1") as CheckBox;
if (CheckBox1.Checked)
{
int bianhaoID = Convert.ToInt32(GridView1.Rows[i].Cells[1].Text);
Response.Redirect("update.aspx?BHID="+bianhaoID);
}
}
} }
{
int nCount = GridView1.Rows.Count;
int nSelectNum = 0;
for (int i = 0; i < nCount; i++)
{
CheckBox CheckBox1 = GridView1.Rows[i].Cells[0].FindControl("CheckBox1") as CheckBox;
if (CheckBox1.Checked)
{
nSelectNum++;
}
}
if (nSelectNum > 1)
{
Response.Write("<script>alert('不能选择多个记录进行修改!')</script>");
}
else
{
nCount = GridView1.Rows.Count;
for (int i = 0; i < nCount; i++)
{
CheckBox CheckBox1 = GridView1.Rows[i].Cells[0].FindControl("CheckBox1") as CheckBox;
if (CheckBox1.Checked)
{
int bianhaoID = Convert.ToInt32(GridView1.Rows[i].Cells[1].Text);
Response.Redirect("update.aspx?BHID="+bianhaoID);
}
}
} }
//
Response.Redirect("update.aspx?BHID="+bianhaoID.ToString());
int bianhaoID = Convert.ToInt32(GridView1.Rows[i].Cells[1].Text);
Response.Redirect("update.aspx?BHID="+bianhaoID); 你不感觉你自己做画蛇添足吗?
格式不对嘛
这段代码太多多余的地方了
Response.Redirect(url); 你看一下这种写法可以吗
要学会自己调试发现问题,然后解决.
int nCount = GridView1.Rows.Count;
int nSelectNum = 0,index = -1;
for (int i = 0; i < nCount; i++)
{
if ((GridView1.Rows[i].Cells[0].FindControl("CheckBox1") as CheckBox).Checked)
{
nSelectNum++;
if (nSelectNum > 1)
{
Response.Write(" <script>alert('不能选择多个记录进行修改!') </script>");
return;
}
index = i;
}
}
if (index != -1)
{
Response.Redirect("update.aspx?BHID=" + GridView1.Rows[i].Cells[1].Text);
}
int nCount = GridView1.Rows.Count;
int nSelectNum = 0, index = -1;
for (int i = 0; i < nCount; i++)
{
if ((GridView1.Rows[i].Cells[0].FindControl("CheckBox1") as CheckBox).Checked)
{
nSelectNum++;
if (nSelectNum > 1)
{
Response.Write(" <script>alert('不能选择多个记录进行修改!') </script>");
return;
}
index = i;
}
}
if (index != -1)
{
Response.Redirect("update.aspx?BHID=" + GridView1.Rows[index].Cells[1].Text);
}