I'm following this C# tutorial for doing some user roles setting in my database and it gives me the following code:
(Line 13 is the trouble line)
1 private void CheckRolesForSelectedUser()
2 {
3 // Determine what roles the selected user belongs to
4 string selectedUserName = UserList.SelectedValue;
5 string[] selectedUsersRoles = Roles.GetRolesForUser(selectedUserName);
6
7 // Loop through the Repeater's Items and check or uncheck the checkbox as needed
8 foreach (RepeaterItem ri in UsersRoleList.Items)
9 {
10 // Programmatically reference the CheckBox
11 CheckBox RoleCheckBox = ri.FindControl("RoleCheckBox") as CheckBox;
12 // See if RoleCheckBox.Text is in selectedUsersRoles
13 if (selectedUsersRoles.Contains<string>(RoleCheckBox.Text))
14 RoleCheckBox.Checked = true;
15 else
16 RoleCheckBox.Checked = false;
17 }
18 }
Well I punch it in and run it and I get a error "'System.Array' does not contain a definition for 'Contains'" (Line 13)
Well the tutorial then says:
Note: The selectedUserRoles.Contains<string>(...) syntax will not compile if you are using ASP.NET version 2.0. The Contains<string> method is part of the LINQ library, which is new to ASP.NET 3.5. If you are still using ASP.NET version 2.0, use the Array.IndexOf<string> method instead.
So I click the link to that array.indexof thing and I just can't figure it out haha.
I've changed that line 13 to something like:
if (Array.IndexOf<string>(selectedUsersRoles, RoleCheckBox.Text))
But I know it's still not right. I haven't really covered much of the C# itself yet, I just realized that I didn't complete a few pages of this tutorial in asp.net & want to do it haha.