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 に答える