日期:2014-05-18  浏览次数:20436 次

奇怪问题```GridView点编辑时绑顶DropDownList时出现的````大家看看!急``
protected   void   GridView1_RowCreated(object   sender,   GridViewRowEventArgs   e)
        {
                if   (e.Row.RowState   ==   DataControlRowState.Edit)
                {
                      ChaKind   chk   =   new   ChaKind();
                      DropDownList   drdl   =   new   DropDownList();
                      drdl   =   (DropDownList)e.Row.Cells[3].FindControl( "DropDownList1 ");
                      drdl.DataSource   =   chk.GetKindds();
                      drdl.DataTextField   =   "cha_kind ";
                      drdl.DataValueField   =   "cha_id ";
                       
                      drdl.DataBind();
                   
                      //((TextBox)e.Row.Cells[1].Controls[0]).MaxLength   =   4;
                     
                }
        }

绑定的代码!!

出现状况:
  就第二行绑定的时候是空值``其他的行都可以绑定```怎么回事?

------解决方案--------------------
既然能出现别的行.
是不是你的drdl.DataSource = chk.GetKindds();返回的数据源就有空行
------解决方案--------------------
就有空值的行

------解决方案--------------------
表中第二行的cha_kind为空
------解决方案--------------------
你循环的每次绑定都把原来的值覆盖了,所以只有一个啊~~用drdl.Items.Add(chk.GetKindds)试试~~~
------解决方案--------------------
这个问题我也遇到过,我也不知道
推荐楼主一个另外的解决办法
你可以在GridViewEditIng事件里面绑定,这样就可以解决了!!!
用户点编辑启动绑定
------解决方案--------------------
if (e.Row.RowState == DataControlRowState.AlternatingItem)
//copy code to here
------解决方案--------------------
或者干脆去掉if语句
------解决方案--------------------
在gridview_rowdatabind事件里对dropdownlist的绑定