where are you calling System.Web.UI.WebControls.DropDownList myDropdown=(DropDownList)e.Item.Cells[2].FindControl("edit_gw");//找到dropdown控件;?? you should be calling inside Update command handler, also, are you sure it is in Cells[2]?
label是itemtemplate,dropdown是eidtitemtamplate,同一个tamplatecolumn里的啊,前面的label能取道, 应该说明“sure it is in Cells[2]”吧? 我这么想的:进入编辑状态,取得dropdownlist,绑定数据,给用户 提供一个选择列表。Update就要更新了,那是我要做的下一步,取得dropdown的被选择项。 显示出来的界面中有dropdownlist控件,是空的。
string labeltext=gwlabel.Text;//取得先前label项的text;
user_list.EditItemIndex=e.Item.ItemIndex;//设置编辑项为被选中项index值
user_list.DataSource=myDataset.Tables["user_table"];
user_list.DataBind();//再次绑定,进入编辑状态;
System.Web.UI.WebControls.DropDownList myDropdown=(DropDownList)e.Item.Cells[2].FindControl("edit_gw");//找到dropdown控件;前面的label取得了,并得到了text的值;
后面的dropdownlist取不到:
System.NullReferenceException: 未将对象引用设置到对象的实例。
哪儿错了?
System.Web.UI.WebControls.DropDownList myDropdown=(DropDownList)e.Item.Cells[2].FindControl("edit_gw");//找到dropdown控件;??
you should be calling inside Update command handler, also, are you sure it is in Cells[2]?
应该说明“sure it is in Cells[2]”吧?
我这么想的:进入编辑状态,取得dropdownlist,绑定数据,给用户
提供一个选择列表。Update就要更新了,那是我要做的下一步,取得dropdown的被选择项。
显示出来的界面中有dropdownlist控件,是空的。