【问题标题】:dropdownlist binding from function in code behind aspx vb来自aspx vb后面代码中的函数的下拉列表绑定
【发布时间】:2010-05-10 23:57:12
【问题描述】:

所以我在 C# 中有这个工作,为什么它不能在 VB 中工作

 public string[] CustomizedRoles()
 {
   int length = Roles.GetAllRoles().Length;
   string[] arrRoles=Roles.GetAllRoles();
   string[] customizedRoles= new string[length+1];
   customizedRoles[0] = "";
   for (int i = 1; i < length+1; i++)
   {
       customizedRoles[i] = arrRoles[i-1];
   }

   return customizedRoles;
}

asp:GridView....

asp:DropDownList ID="ddlOwnerRolesUpdate" runat="server" DataSource="" Height="25px" Width="177px" SelectedValue=''>

“所有者”在哪里是来自网格数据源的数据值

它在 C# 中运行良好。

在 Vb 中使用相同的 aspx,但它后面的代码不起作用。

Public Function CustomizedRoles() As String()
    Dim length As Integer = Roles.GetAllRoles().Length
    Dim arrRoles As String() = Roles.GetAllRoles()
    Dim _customizedRoles As String() = New String(length + 1) {}
    _customizedRoles(0) = " "

    For index As Integer = 1 To length
        _customizedRoles(index) = arrRoles(index - 1)
    Next
    Return _customizedRoles
End Function

谁能告诉我如何将字符串数组绑定到下拉列表,从 aspx 到 VB 中的代码

【问题讨论】:

    标签: data-binding


    【解决方案1】:

    我发现 VB.NET 无法将空值绑定到下拉列表我的代码有一个错误,由于数组初始化而生成空值: Dim _customizedRoles As String() = New String(length + 1) {} // 它应该只是长度

    解决这个问题后,它工作正常,只是一个提示,C# 比 VB 做更多自动的事情,所以不要指望 VB 会做 C# 默认做的事情。

    Public Function CustomizedRoles() As String()
        Dim length As Integer = Roles.GetAllRoles().Length
        Dim arrRoles As String() = Roles.GetAllRoles()
        Dim _customizedRoles As String() = New String(length) {}
        _customizedRoles(0) = " "
        For index As Integer = 1 To length
            _customizedRoles(index) = arrRoles(index - 1)
        Next
        Return _customizedRoles
    End Function
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-21
      • 2011-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-08
      • 1970-01-01
      相关资源
      最近更新 更多