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

含代码 VB.NET动态生成DROPDOWNLIST 里的数据 ,请问我错在哪里?

Dim StrSkill As String
  Dim objDataTalbe As DataTable
  ' Dim Tablerows As DataRow
  Dim ddl As DropDownList

  ' 对每行数据遍历
  For Each objRow As GridViewRow In Me.GridView1.Rows

  StrSkill = objRow.Cells(0).Text

  objMDL = objBLL.getDdlSkillLevel(StrSkill)

  objDataTalbe = objMDL.ddlSkillLevel ‘得到了一列名为'SKILL_LEVEL'的数据

  ' 获得在GRIDVIEW里面的下拉框
  ddl = DirectCast(Me.GridView1.FindControl("classLevel"), DropDownList)
  ’在这里绑定数据 出异常 ,Object reference not set to an instance of an object.
  ddl.DataSource = objDataTalbe
  ddl.DataTextField = "skill_level"
  ddl.DataValueField = "skill_level"
   
  Next

请问 我通过这样遍历 GRIDVIEW 能实现 对下拉框的动态生成吗

我这样做对不对



------解决方案--------------------
ddl = DirectCast(Me.GridView1.FindControl("classLevel"), DropDownList) 
改成这样 ddl = DirectCast(objRow.FindControl("classLevel"), DropDownList)