我有这个代码,在单击按钮时,我想获取每行中选中的所有复选框的 Empid。但字符串变量 str 始终为空且不带任何值。为什么会这样?好心的帮助
protected void btn_3id_Click(object sender, EventArgs e)
{
string str = "";
string srr = "";
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox chk = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
if (chk.Checked)
{
if (str == "")
{
str = GridView1.Rows[i].Cells[0].Text.ToString();
}
else
{
srr = str + "," + GridView1.Rows[i].Cells[1].Text.ToString();
}
}
}
Session["card_id"] = str;
Response.Redirect("ID.aspx");
}
}