0

我有这个代码,在单击按钮时,我想获取每行中选中的所有复选框的 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");
    }
}
4

1 回答 1

2

如果您的控件名称是 Label 然后使用

str = ((Label)GridView1.Rows[i].FindControl("yourlabelid")).Text;

代替

str = GridView1.Rows[i].Cells[0].Text.ToString(); 
于 2013-03-20T07:51:31.553 回答