所以我在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 =“&lt;%#CustomizedRoles()%&gt;”高度=“25px”宽度=“177px”SelectedValue ='&lt;%#Bind(“所有者”)%&gt;'&gt;
其中“所有者”是来自网格数据源的数据值
它在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后面的代码中的下拉列表
答案 0 :(得分:0)
我发现VB.NET无法将空值绑定到dropdownlist,我的代码有错误,由于数组初始化而产生空值: Dim _customizedRoles As String()=新字符串(长度 + 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