请问为什么会这样?
我在DataGrid中放了一个TemplateColumn,里面是一个DropDownList,然后我用代码访问这个DropDownList,下面是我在EditCommand中写的代码,我想在点编辑按钮的时候给这个DropDownList加入数据源,结果总是无法得到这个对象的正确引用。dt总是等于空。
<HTML代码>
<asp:TemplateColumn HeaderText="部门">
<EditItemTemplate>
<asp:DropDownList id="editDepart" runat="server" Width="173px"> </asp:DropDownList> </EditItemTemplate>
</asp:TemplateColumn>
Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgUsers.EditCommand
dgUsers.EditItemIndex = e.Item.ItemIndex
Dim dt As DropDownList = CType(e.Item.Cells(6).FindControl("editDepart"), DropDownList)
If dt Is Nothing Then
Label1.Text = "Edit:dt is null"
Else
dt.DataSource=....
dt.DataBind()
End If
End Sub