ASP.NET:将ListItem集合加载到Footer模板DropDownList

时间:2016-08-03 14:44:35

标签: asp.net vb.net gridview

我无法在GridView中填充页脚模板字段的下拉列表,我的工作是:

<asp:TemplateField HeaderText="Vendor Country" SortExpression="VENDOR_COUNTRY">
    <EditItemTemplate>
    <asp:TextBox ID="TextBox21" runat="server" Text='<%# Bind("VENDOR_COUNTRY") %>'></asp:TextBox>
    </EditItemTemplate>
    <ItemTemplate>
      <asp:Label ID="Label37" runat="server" Text='<%# Bind("VENDOR_COUNTRY") %>'></asp:Label>
    </ItemTemplate>
    <FooterTemplate>
       <asp:DropDownList ID="ddVendorCountry" runat="server" DataTextField="Text" DataValueField="Value" Font-Size="Small">
                                           </asp:DropDownList>
    </FooterTemplate>
    </asp:TemplateField>

然后我在后面的代码中有一个函数来获取listitems列表(我将使用它三次):

  Public Function GetCountries() As List(Of ListItem)

        Dim countryList As New List(Of ListItem)
        countryList.Add(New ListItem("AF", "AF"))
        countryList.Add(New ListItem("AX", "AX"))
        (...)
  End Function

我试图在Page_Load,gridview RowDataBound,gridview DataBound事件中加载它... notccessfuly:

 Protected Sub gvData_DataBound(sender As Object, e As EventArgs) Handles gvData.DataBound
    Dim ddlCountries As DropDownList = TryCast(gvData.FooterRow.FindControl("ddVendorCountry"), DropDownList)
    ddlCountries.DataSource = GetCountries()
    ddlCountries.DataBind()
End Sub

我曾经使用Razor处理MVC模式,但现在我必须拯救一个旧网页,尽管在.NET平台内我迷失了......

感谢您的建议

0 个答案:

没有答案