updatapanel中有若干的asp:checkbox
想根据这些checkbox是否选中更新数据库的字段
并且每个checkbox要对应相应的字段,中间的方法我有点想不出来,麻烦大家帮帮忙。foreach (Control ctrl in upCkboxGl.ContentTemplateContainer.Controls)
            {                string type = ctrl.GetType().ToString();
                if (type == "System.Web.UI.WebControls.CheckBox")
                {
                    
                    if (((System.Web.UI.WebControls.CheckBox)ctrl).Checked == true)
                    {
                       
                    }
                }            }

解决方案 »

  1.   

    checkbox 中 有个text 属性的 
    直接 托 控件 SQLDataSourse 进行设置 其中有一个 NONE 把他 改成ControlID 选择下 就可以在 里面自动读取值了 然后 更新 数据库字段
      

  2.   

    可以考虑用checkboxlist绑定数据源来实现
      

  3.   

    判断类型可以用这个不需要判断字符串if(ctrl is CheckBox)}{}
    可以把数据库字段名存放在checkbox上然后拼接一个sql更新
      

  4.   

    我这里有单选按钮的代码,和CheckBox 应该一样的,其实就是那一句IF 判断而已,
    为了让你看的明白一些我就贴多一点代码,也是根据选中的单选按钮来获得那一行里面某一些值。你看看:
    PhilipModel pm_model = new PhilipModel();
                int index;
                for (int i = 0; i < this.GV.Rows.Count; i++)
                {
                    if (((RadioButton)GV.Rows[i].Cells[1].FindControl("RadioButton1")).Checked)
                    {
                        index = GV.Rows[i].RowIndex;                    if (Session["UserGroup"].ToString() == "B5 PMC")
                        {
                            if (this.txtQTY.Text.Trim() == "" || this.txtPlannerlatest.Text.Trim() == "" || this.txtStausfromPMC.Text.Trim() == "" || this.txtPlnnerDate.Text.Trim() == "")
                            {
                                this.lblMessage.Text = "State:Incomplete Information";
                                this.lblMessage.ForeColor = Color.Red;
                                return;
                            }
                            else
                            {
                                pm_model.PMT_Re1 = "";                            pm_model.PlannerLatest1 = txtPlannerlatest.Text.Trim();
                                pm_model.SoQty1 = txtQTY.Text.Trim();
                                pm_model.Re1 = txtRe.Text.Trim();
                                pm_model.ShipPed1 = "";                            pm_model.StausPMC1 = txtStausfromPMC.Text.Trim();
                                pm_model.FactoryDate1 = "";
                                pm_model.PlannerDate1 = txtPlnnerDate.Text.Trim();
                            }
                        }
                        if (Session["UserGroup"].ToString() == "B5 PMT")
                        {                        if (this.txtPMTRe.Text.Trim() == "" || this.txtFactorydata.Text.Trim() == "" || this.txtshipPed.Text.Trim() == "")
                            {
                                this.lblMessage.Text = "State:Incomplete Information";
                                this.lblMessage.ForeColor = Color.Red;
                            }
                            else
                            {
                                pm_model.PMT_Re1 = this.txtPMTRe.Text.Trim();
                                pm_model.PlannerLatest1 = "";
                                pm_model.SoQty1 = "";
                                pm_model.Re1 = "";
                                pm_model.ShipPed1 = this.txtshipPed.Text.Trim();
                                pm_model.StausPMC1 = "";
                                pm_model.FactoryDate1 = this.txtFactorydata.Text.Trim();
                                pm_model.PlannerDate1 = "";
                            }
                        }                    pm_model.SoNo1 = GV.Rows[i].Cells[2].Text.Trim();
                        pm_model.PoNo1 = GV.Rows[i].Cells[6].Text.Trim();
                        pm_model.SoLine1 = GV.Rows[i].Cells[7].Text.Trim();
                        pm_model.PoLine1 = GV.Rows[i].Cells[8].Text.Trim();
                        pm_model.VtechPN1 = GV.Rows[i].Cells[4].Text.Trim();                    if (new PhilipManager().UserInputPhilipInfo(pm_model))
                        {
                            this.lblMessage.Text = "State:Success";
                            this.lblMessage.ForeColor = Color.Green;
                        }
                        else
                        {
                            this.lblMessage.Text = "State:Error";
                            this.lblMessage.ForeColor = Color.Red;
                        }
                    }
                }