提交单击时,未检查gridview中的复选框为true

时间:2014-01-30 07:06:32

标签: c# asp.net

提交点击时未检查gridview中的

复选框为false但是当我修改和更新按钮时单击选中则为TRUE

public void addchapselect()
{
    TextBox1.Text = "";

    for (int i = 0; i < gvChapter.Rows.Count; i++)
    {

        CheckBox chkbox = (CheckBox)gvChapter.Rows[i].Cells[0].FindControl("chkSelect");
        if (chkbox != null)
        {
            if (chkbox.Checked)
            {

                TextBox1.Text += Convert.ToString(gvChapter.Rows[i].Cells[0].Text) + ",";

                // ItemValueId = ItemValueId + ",";
                string Name = Convert.ToString(gvChapter.Rows[i].Cells[1].Text);



            }
        }
        chkbox.Checked = false;
    }
    if (TextBox1.Text != "")
        TextBox1.Text = TextBox1.Text.Substring(0, TextBox1.Text.Length - 1);
}

1 个答案:

答案 0 :(得分:1)

原因可能是您在Gridview函数上绑定了page_load

将其绑定在!IsPostback内,它应该有效。

if (Page.IsPostBack)
{
    //bind your grid here.
 }