我的gridview中有一个checkBoxField,用来显示bool数据,现在要实现,当客房点击更新数据时checkboxField变成可编辑状态。
我想在Rowupdateng中更新他们字段的值;但不知道怎么得到checkBoxField的值;
    protected void More_Chanpin_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
    这里应该怎么写才能得到checkBoxField的值;
 
    }

解决方案 »

  1.   

    定义checkBox变量,用findcountrol找到控件以后强制转换成checkBox初始化变量。就可以获取到值了。
      

  2.   

    这样吗?
    CheckBox Cb = (CheckBox)More_Chanpin.Rows.[e.RowIndex].cells[11].FindControl("xpss");
    但是我在
      <asp:CheckBoxField DataField="sj_cp_xpss"   HeaderText="新品推荐"  id="xpss" SortExpression="sj_cp_xpss" />加id="xpss"调式的时候提示这样的错语错误 2 类型“System.Web.UI.WebControls.CheckBoxField”不具有名为“id”的公共属性。 E:\chinamobile\chinamobile_sysadmin\center\More_Sys_Chanpin.aspx 44
      

  3.   

    我用的时候怎么没出现问题啊? protected bool FindCheckBox()
        { 
            //判断用户是否已经选中某条记录
            if (GridView1.Rows.Count > 0)
            {
                for (int i = 0; i < GridView1.Rows.Count; i++)
                {
                    CheckBox chbx= (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
                    if (chbx.Checked == true)
                    {
                        //设置DIV各个控件的值并返回真
                        userid.Text = GridView1.Rows[i].Cells[1].Text.ToString().Trim();
                        username.Text = GridView1.Rows[i].Cells[2].Text.ToString().Trim();
                        phone.Text = GridView1.Rows[i].Cells[4].Text.ToString().Trim();
                        if (GridView1.Rows[i].Cells[3].Text.ToString().Trim() == "管理员")
                        {
                            //
                            usertype.SelectedIndex = 1;
                        }
                        else
                        //if (GridView1.Rows[i].Cells[4].Text.ToString().Trim() == "普通用户")
                        {
                            //如果用户是普通用户或者其他未知类型用户则统一设置为普通用户
                            usertype.SelectedIndex = 0;
                        }
                        for (int j = 0; j < Placeid.Items.Count; j++)
                        {
                            //判断placeid设置div中的selectindex
                            if(GridView1.Rows[i].Cells[6].Text.ToString().Trim() == Placeid.Items[j].Value.ToString())
                            {
                                //
                                Placeid.SelectedIndex = j; 
                                break;
                            }
                        }//end of for
                        return true;
                    }//end of if
                    //else
                    //{
                    //    //返回false并给出提示                //    ScriptManager.RegisterClientScriptBlock(UpdatePanel1, typeof(UpdatePanel), "PLSSelectItem", "alert('请选择一条记录然后再进行操作!')", true);
                    //    return false;
                      
                    //}
                }//end of for
            }//end if if        //如果gridview的行数小于1,直接返回false
            ScriptManager.RegisterClientScriptBlock(UpdatePanel1, typeof(UpdatePanel), "PLSSelectItem", "alert('请选择一条记录然后再进行操作!')", true);
            return false;
            
        }
        //判断用户是否选中某条记录结束