如何在Gridview行中识别DropDownList以填充它

时间:2019-04-04 19:21:00

标签: gridview drop-down-menu edititemtemplate

我必须支持一个我没有写过的应用程序,而且多年来我还没有做过VB.Net。 我有一个只有1列数据和“编辑”按钮的手动填充的gridview。我想填充DDL(在EditItemTemplate中)(从技术上讲,我有工作代码),但是每次我尝试使用'FindControl'时,'d'参数始终为空。

If e.Row.RowType = DataControlRowType.DataRow Then
    If e.Row.RowState And DataControlRowState.Edit > 0 Then
        Dim d As DropDownList = CType(e.Row.FindControl("ddl"), DropDownList)

        fillddl(d)
    End If
End If

Protected Sub fillddl(d As DropDownList)
    Dim years As List(Of Integer) = New List(Of Integer)()
    Dim currentYear As Integer = DateTime.Now.Year
    Dim startYear As Integer = 2011
    For year As Integer = startYear To currentYear
        years.Add(year)
    Next
    d.DataSource = years
    d.DataBind()
End Sub

0 个答案:

没有答案