哪位高手帮忙给看一下!在Gridview中建两个模版列,一个是dropdownlist,另一个是RadioButtonList;奇怪的是运行时RadioButtonList的值就是取不了,显示为空?而dropdownlist就是默认值,而不是选择值,为什么呢?急死了,同样的做法,在另一个页面就没出错!好奇怪!找了两天也没找出错误来!
 protected void SmartGridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
       
        DropDownList DDLSize;
        RadioButtonList RBLDesign;        if (((DropDownList)e.Row.FindControl("DDLSize")) != null)
        {            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string hpmc = e.Row.Cells[3].Text;//取得护品名称               
                string SelHpdh = "select hpdh from hpdhmc where hpmc='" + hpmc + "'";
                string Hpdh = Convert.ToString(MyDb.ReturnSQL(SelHpdh));//根据护品名称,获取护品代号
                DDLSize = (DropDownList)e.Row.FindControl("DDLSize") as DropDownList;
                RBLDesign = (RadioButtonList)e.Row.FindControl("RBLDesign") as RadioButtonList;
                if (he.IsSex(Hpdh))
                {
                    RBLDesign.Visible = true;                }
                else
                {
                    RBLDesign.Visible = false;                }
                if (he.IsSizes(Hpdh))
                {                    DDLSize.DataSource = MyDb.DT("select distinct a.sizes from sizes a,hpdhmc b,emp_goods c where a.styles=b.sizes and b.hpdh=c.hpdh and c.hpdh='" + Hpdh + "'");
                    DDLSize.DataValueField = "sizes";
                    DDLSize.DataTextField = "sizes";
                    DDLSize.DataBind();
                }
                else
                {
                    DDLSize.Visible = false;
                }
                DDLSize.SelectedValue = ((HiddenField)e.Row.FindControl("HDFSize")).Value;            //选中 DropDownList
                RBLDesign.SelectedValue = ((HiddenField)e.Row.FindControl("HDFDesign")).Value;
            }
        }
    }  //绑定dropdownlist
protected void Button1_Click(object sender, EventArgs e)
    {
        System.Threading.Thread.Sleep(3000);
        foreach (GridViewRow gvr in SmartGridView1.Rows)
        {
            string[] SelDiv = he.SelectDhKh(Session["username"].ToString());
            string Dh = SelDiv[1];//获取队号            string id = gvr.Cells[0].Text;//获取员工姓名
           
            string gzmc = gvr.Cells[2].Text;
            string SqlGzdh = "select gzdh from gzdhmc where gzmc='" + gzmc + "'";
            string Gzdh = Convert.ToString(MyDb.ReturnSQL(SqlGzdh));//获取工种代码            string hpmc = gvr.Cells[3].Text;
            string SqlHpdh = "select hpdh from hpdhmc where hpmc='" + hpmc + "'";
            string Hpdh = Convert.ToString(MyDb.ReturnSQL(SqlHpdh));//获取护品代码            string Sizes = ((DropDownList)gvr.Cells[5].FindControl("DDLSize") as DropDownList).SelectedValue;//获取选定尺寸            string Design = ((RadioButtonList)gvr.Cells[6].FindControl("RBLDesign") as RadioButtonList).SelectedValue;
            //获取发放数量
            string SqlAmo = "select b.ffsl from emp_goods a,gzhpnxk b where a.gzdh=b.gzdh and a.hpdh=b.hpdh and a.hpdh= '" + Hpdh + "' and a.name = '" + id + "' and a.gzdh = '" + Gzdh + "'";
            string Amount = Convert.ToString(MyDb.ReturnSQL(SqlAmo));            
            
            //根据选定值更新库数据
            string SqlUp = "update emp_goods set sizes='" + Sizes + "',design='" + Design + "',Amount='" + Amount + "' where dh='"+Dh+"' and hpdh= '" + Hpdh + "' and name = '" + id + "'";
            
            try
            {                MyDb.NoreturnSql(SqlUp);
                GridViewDataBind();            }
            catch (Exception ex)
            {
                Response.Write("数据库错误,错误原因:" + ex.Message);
                Response.End();
            }        }
        Label1.Text = "已经成功保存全部修改!";    }//批量更新数据

解决方案 »

  1.   

    Gridview 看一件控件的事页是否还绑定在。Gridview 有时会把事件丢失的。如果没有丢失事件。你设个断点跟踪一下。
      

  2.   

    你的gridview绑定事件是不是没放在if(!IsPostBack){}
    里面??  如果没放在那里面的话就有课能在你刷新页的时候把你在dropdownlist中选择的项刷没了
      

  3.   

    RadioButtonList 你是否填充了数据集
    如果 RadioButtonList 的 Items 集合是空 即使复制 也没作用的吧
      

  4.   

    设置断点看看数据是否有,还有就是数据绑定是否在IsPostBack里