Author Topic: Looking for quick help haha.  (Read 11607 times)

0 Members and 1 Guest are viewing this topic.

Offline OMGBurgersTopic starter

  • Hero Member
  • *
  • Posts: 800
  • Activity:
    0%
  • Reputation Power: 7
  • OMGBurgers has no influence.
  • Respect: +44
  • Referrals: 0
    • View Profile
Looking for quick help haha.
« on: August 13, 2008, 09:28:50 PM »
0
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)
Code: [Select]
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:
Quote
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:
Code: [Select]
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.

Offline OMGBurgersTopic starter

  • Hero Member
  • *
  • Posts: 800
  • Activity:
    0%
  • Reputation Power: 7
  • OMGBurgers has no influence.
  • Respect: +44
  • Referrals: 0
    • View Profile
Re: Looking for quick help haha.
« Reply #1 on: August 13, 2008, 10:16:11 PM »
0
Ok so I came up with this:

if (Array.IndexOf<string>(selectedUsersRoles, RoleCheckBox.Text) != -1)

I went ahead and ran it and had no errors so no idea... lol.  I'll do the next part real quick which sets the roles & give it a go and see if it loads correctly.

Offline OMGBurgersTopic starter

  • Hero Member
  • *
  • Posts: 800
  • Activity:
    0%
  • Reputation Power: 7
  • OMGBurgers has no influence.
  • Respect: +44
  • Referrals: 0
    • View Profile
Re: Looking for quick help haha.
« Reply #2 on: August 13, 2008, 10:26:01 PM »
0
And just to tripple post....

It works! hah.

It loads them up perfectly.  I don't really know exactly how i came up with that since i have no clue what that <string> part means ;(.  All I know is it returns a value as far as the location of the rolecheckbox.text inside the selecteduserroles string.

Eh oh well.  One day ill laugh at this!

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13301
  • Activity:
    0%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Looking for quick help haha.
« Reply #3 on: August 13, 2008, 11:55:48 PM »
0
For the first example you posted, you can just probably get rid of the <string> all together because that information is implied in the array selectedUsersRoles.
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline OMGBurgersTopic starter

  • Hero Member
  • *
  • Posts: 800
  • Activity:
    0%
  • Reputation Power: 7
  • OMGBurgers has no influence.
  • Respect: +44
  • Referrals: 0
    • View Profile
Re: Looking for quick help haha.
« Reply #4 on: August 14, 2008, 09:15:28 AM »
0
I can't wait to get started with the C# tutorials.  Then I won't have this problem hopefully haha.  3 pages of this asp.net stuff left.  I wana learn the c# after I set up all this basic crap so I can go back in and fine tune all these arguments, add in more, etc.  So long as I know it functions now I'm set lol.

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13301
  • Activity:
    0%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Looking for quick help haha.
« Reply #5 on: August 14, 2008, 09:29:50 AM »
0
Yah, it's been a fun experience for me.  There are several language constructs that I've always wished were available in other languages.  Collections are something that I love and have always been responsible for creating myself, but you get them for free.  So things like Dictionaries, Lists, Stacks make data storage/manipulation a breeze.
Please read the ScriptUO site RULES
Come play RIFT with me!

Tags: