感谢文章作者:http://blog.csdn.net/ccp5780199/article/details/1904407
在点GridView的编辑按钮时候 对DropDownList的数据进行绑定.
DropDownList所在的列是摸板列,
在RowEditing事件下如下源码
DropDownList ddl = this.GridViewMemberAccount.Rows[e.NewEditIndex].Cells[0].Controls[1] as DropDownList;
DropDownListHelper.BindMember(ddl);
this.GridViewMemberAccount.EditIndex = e.NewEditIndex;
this.GridViewDataBind();
这样会报错,提示未将对象引用到对象的实例 找不到dropDownList
要先绑定GridView的数据再绑定DropDownList.
this.GridViewMemberAccount.EditIndex = e.NewEditIndex;
this.GridViewDataBind();
DropDownList ddl = this.GridViewMemberAccount.Rows[e.NewEditIndex].Cells[0].Controls[1] as DropDownList;
DropDownListHelper.BindMember(ddl);
但原因不 明, 不知道是不是没绑定数据前 控件是未被实例化?