改正一下check()
Sub check(ByVal sender As System.Object, ByVal e As System.EventArgs)
            'CType(Datagrid1.FindControl("ddl_gn")为页脚的控件
            Dim a As DropDownList = CType(Datagrid1.FindControl("ddl_gn"), DropDownList)
            If a.SelectedItem.Text = "超级用户" Then                'CType(Datagrid1.FindControl("txt_bz")为页脚的控件
                Dim b As TextBox = CType(Datagrid1.FindControl("txt_bz"),TextBox)
                b.Text = a.SelectedItem.Text
            End If
            End Sub
---------------------------------------------------------------------

解决方案 »

  1.   

    Protected WithEvents ddl_gn As System.Web.UI.WebControls.DropDownListSub check(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles ddl_gn.SelectedIndexChanged
    不会有什么问题的
      

  2.   

    scong(歪弓射貂) 
    为什么要这样写?不是很明白
    ddl_gn是(datagrid)中页脚的子控件
    可以讲讲码?
      

  3.   

    无论是自己写的还是按照scong(歪弓射貂) 的提示总会出现相同的问题
    -------------------------------------------------------------------------------
    未将对象引用设置到对象的实例。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 
    行 156:        'Dim cc As DataRow = Datagrid1.FindControl("ddl_gn")
    行 157:        'Dim b As DropDownList = CType(a.FindControl("ddl_gn"), DropDownList)
    行 158:        If CType(Datagrid1.FindControl("ddl_gn"), DropDownList).SelectedItem.Text = "超级用户" Then
    行 159:            Dim c As TextBox = CType(Datagrid1.FindControl("txt_bz"), TextBox)
    行 160:            c.Text = "9999"
     源文件: E:\_asp.net_\dropdownlist_test\WebForm1.aspx.vb    行: 158 堆栈跟踪: 
    [NullReferenceException: 未将对象引用设置到对象的实例。]
       dropdownlist_test.WebForm1.check(Object sender, EventArgs e) in E:\_asp.net_\dropdownlist_test\WebForm1.aspx.vb:158
       System.Web.UI.WebControls.ListControl.OnSelectedIndexChanged(EventArgs e)
       System.Web.UI.WebControls.DropDownList.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent()
       System.Web.UI.Page.RaiseChangedEvents()
       System.Web.UI.Page.ProcessRequestMain() +1070 
    --------------------------------------------------------------------------------
    版本信息: Microsoft .NET 框架版本:1.0.3705.0; ASP.NET 版本:1.0.3705.0
      

  4.   

    Dim a As new DropDownList = CType(Datagrid1.FindControl("ddl_gn"), DropDownList)