使用c#在网格视图中选中复选框选择和取消选择

时间:2014-04-05 04:51:51

标签: c# asp.net gridview

我有三个语言能力复选框(读,写, 在网格视图中使用c#asp.net框架工作4,记录是 在chk框选择或de选择上保存是或否。当我加载 网格或编辑行根据我的选择未选中复选框 然而,使用调试模式记录所有代码都正常执行。我在这 我发布了代码:

protected void grdUCempLanguage_RowDataBound(object sender, GridViewRowEventArgs e)
{
    EmpLanguageDAO  empLanguageDAO = new EmpLanguageDAO ();

    ResponseDTO responseDTO = empLanguageDAO.LoadLanguages();
    ResponseDTO responseDTo = FillChkBox(_empID);

    if (e.Row.RowType == DataControlRowType.DataRow)
    {

        DropDownList ddlLanguage = (DropDownList)e.Row.FindControl("ddLanguageUCemplanguage");

        if (responseDTO.Status)
        {
            if (ddlLanguage != null)
            {
                ddlLanguage.Items.Clear();
                ddlLanguage.DataSource = responseDTO.ResultSet.Tables[0];
                ddlLanguage.DataTextField = "Language";
                ddlLanguage.DataValueField = "LangId";
                ddlLanguage.DataBind();
            }

            if (responseDTo.Status && responseDTo.RecordID > 0)
            {
                if (_count <responseDTo.ResultSet.Tables[0].Rows.Count)
                {
                    CheckBox chkRead = e.Row.FindControl("chLanguageRead") as CheckBox;

                    if (responseDTo.ResultSet.Tables[0].Rows[_count]["Read"].ToString() == "Yes")

                        chkRead.Checked = true;                       

                    else

                        chkRead.Checked = false;
                    }

                    CheckBox chkwrite = (CheckBox)e.Row.FindControl("chLanguageWrite");
                    if (responseDTo.ResultSet.Tables[0].Rows[_count]["Write"].ToString() == "Yes")

                        chkwrite.Checked = true;
                        //(e.Row.FindControl("chLanguageWrite") as CheckBox).Checked = true;

                    else
                       chkwrite.Checked = false;
                        //(e.Row.FindControl("chLanguageWrite") as CheckBox).Checked = false;

                     CheckBox chkspeak = (CheckBox)e.Row.FindControl("chLanguageSpeak");
                    if (responseDTo.ResultSet.Tables[0].Rows[_count]["Speak"].ToString() == "Yes")           
                        chkspeak.Checked = true;

                    else                  
                       chkspeak.Checked = false;                       

            }
        }               
            _count = _count + 1;
    }

    else if (e.Row.RowType == DataControlRowType.Footer)
    {

        DropDownList ddlLanguage = (DropDownList)e.Row.FindControl("ddLanguageUCemplanguage");
        ddlLanguage.DataSource = responseDTO.ResultSet.Tables[0];
        ddlLanguage.DataBind();

    }

}


protected void grdUCempLanguage_RowCreated(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        CheckBox chkRead = new CheckBox();
        chkRead.EnableViewState = true;
        chkRead.Enabled = true;
        chkRead.Checked = false;
        chkRead.ID = "chLanguageRead";
        e.Row.Cells[1].Controls.Add(chkRead);

        CheckBox chkWrite = new CheckBox();
        chkWrite.EnableViewState = true;
        chkWrite.Enabled = true;
        chkWrite.Checked = false;
        chkWrite.ID = "chLanguageWrite";
        e.Row.Cells[2].Controls.Add(chkWrite);

        CheckBox chkSpeak = new CheckBox();
        chkSpeak.EnableViewState = true;
        chkSpeak.Enabled = true;
        chkSpeak.Checked = false;
        chkSpeak.ID = "chLanguageSpeak";
        e.Row.Cells[3].Controls.Add(chkSpeak);
    }
    e.Row.Cells[2].Controls.Add(chkWrite);

    CheckBox chkSpeak = new CheckBox();
    chkSpeak.EnableViewState = true;
    chkSpeak.Enabled = true;
    chkSpeak.Checked = false;
    chkSpeak.ID = "chLanguageSpeak";
    e.Row.Cells[3].Controls.Add(chkSpeak);
}

0 个答案:

没有答案