SitePoint Sponsor

User Tag List

Results 1 to 12 of 12

Thread: Repeater tag problem

  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Repeater tag problem

    I'm building a site for football predictions and I'd like to create a page that displays all the past fixtures and results.

    At the moment my repeater works fine and displays data such as home team name, away team name, date of fixtures, score, etc.

    The problem is that I'd like to be able to display the names of the goal scorers as well. This is slightly trickier as it can be none to many goal scorers for any given match.

    Is it possible for me to display the names of the goal scorers within the same repeater tag?

    I should probably mention that the data I have bound to the repeater tag is from one database table (with a few inner joins) that holds all the info I need except the scorers. They are held in a seperate table with a foreign key linking it back to the fixtures table.

    Any help would be appreciated, thanks
    Last edited by eatme; Dec 20, 2007 at 16:42.

  2. #2
    SitePoint Zealot Lars's Avatar
    Join Date
    Jun 2000
    Location
    Denmark
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could nest a repeater displaying goal scorers for each row.

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's something I've considered, the only problem is that I already have a nested repeater. The outer repeater tag displays the details of the fixtures and the inner nested repeater displays all the site members' predictions for that match.

    Is that my only option, to have a third nested repeater?

  4. #4
    SitePoint Wizard
    Join Date
    Feb 2007
    Posts
    1,273
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What's wrong with a 3rd repeater. Presumably it would sit alongside the already nested repeater?

  5. #5
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've managed to get the repeater tag working fine now.

    The next issue I have is displaying certain goal scorers depending on the type of goal. I have it set up so that I've created a relationship between two data tables in my code behind file. The first table displays all the details of each fixture with a MatchID. This MatchID is then related to the second table that shows each goal scorer for that fixture.

    Also in the second table I have details of whether it was a standard goal, a penalty or an own goal. Say for example it was a penalty, then I'd like to be able to add the text "(pen)" after their name. Is there someway of creating a switch or set of if statements eith in the code behind file or in the repeater or label tag so I can do this?

    Thanks
    Last edited by eatme; Dec 21, 2007 at 10:38.

  6. #6
    SitePoint Wizard
    Join Date
    Feb 2007
    Posts
    1,273
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How is the goal type represented in the table?

  7. #7
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are 3 types:

    Goal, Penalty and OG. All of type int. So for example, if I scored two goals and a penalty, it would be represented as:

    Goal | Penalty | OG
    2 | 1 | 0

  8. #8
    Back in Action Winged Spider's Avatar
    Join Date
    Jun 2001
    Location
    outside my mind
    Posts
    900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use the OnItemDataBound Method on your repeater.

    There are plenty of tutorials out there about using this method.


  9. #9
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot for that. That seems to be exactly what I need. I've had a look around for some tutorials, but I can't find one to sort my next problem out.

    How do I access the columns within the my data table? This was created in a previous method.

    For example, I need to somehow say if Penalty > 0 then add "(Pen)" after the goal scorer's name

    This is the code I have so far:

    Code Csharp:
        protected void Goal_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            // Return if NOT the following logic for Items and Alternating Items.
            if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType !=
                ListItemType.AlternatingItem)
                return;
     
            Label hsLbl = (Label)e.Item.FindControl("homeScorerLabel");
     
        }

    I know I can access table columns as: ds.Tables["HomeGoals"].Columns["Penalty"], but I can't seem to call "HomeGoals" in the event method Goal_ItemDataBound. Do you know how I can do this?

  10. #10
    Back in Action Winged Spider's Avatar
    Join Date
    Jun 2001
    Location
    outside my mind
    Posts
    900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not 100% sure my code is right, last time I used this was in VB but its probably something like:

    ( might need some casting )

    Code Csharp:
     
     
          if ( DataBinder.Eval( e.Item.DataItem, "WhateverYourGoalColumnIs" ) > 0  )
          {
           hsLbl.Text = "(Pen)" + DataBinder.Eval( e.Item.DataItem, "PlayerName"  ); 
          }
          else 
          {
          }
     
        }

    Quote Originally Posted by eatme View Post
    Thanks a lot for that. That seems to be exactly what I need. I've had a look around for some tutorials, but I can't find one to sort my next problem out.

    How do I access the columns within the my data table? This was created in a previous method.

    For example, I need to somehow say if Penalty > 0 then add "(Pen)" after the goal scorer's name

    This is the code I have so far:

    Code "Csharp":
        protected void Goal_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            // Return if NOT the following logic for Items and Alternating Items.
            if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType !=
                ListItemType.AlternatingItem)
                return;
     
            Label hsLbl = (Label)e.Item.FindControl("homeScorerLabel");
     
        }

    I know I can access table columns as: ds.Tables["HomeGoals"].Columns["Penalty"], but I can't seem to call "HomeGoals" in the event method Goal_ItemDataBound. Do you know how I can do this?


  11. #11
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great thanks, that was pretty much spot on

  12. #12
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you know how I can find out how many goal scorers there are by looking at:

    Code Csharp:
    e.Item.ItemIndex

    It's because I'd like to know who the last person is so I can place a ";" or ")" afterwards.

    This is some of my code so far:

    Code Csharp:
    protected void Goal_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            // Return if NOT the following logic for Items and Alternating Items.
            if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType !=
                ListItemType.AlternatingItem)
                return;
     
             Label hsLbl = (Label)e.Item.FindControl("homeScorerLabel");
     
            // Create new vars for goal type
            int goal;
            int pen;
            int og;
            string name;
     
            goal = (int)(DataBinder.Eval(e.Item.DataItem, "[\"Goal\"]"));
            pen = (int)(DataBinder.Eval(e.Item.DataItem, "[\"Penalty\"]"));
            og = (int)(DataBinder.Eval(e.Item.DataItem, "[\"OG\"]"));
            name = (string) DataBinder.Eval(e.Item.DataItem, "[\"scorer_name\"]");
     
            if ((int)e.Item.ItemIndex == 0)
            {
                hsLbl.Text += "(";
            }
            else
            {
                hsLbl.Text += ", ";
            }
     
     
            // Format goal scorers based on types of goals
            // SOME CODE...
     
        }

    As you can see, if the it's the first person in the array then place an open bracket, if it's not, then place a comma. I want to be able to place a closed bracket after the last person.

    Is it possible to do it using e.Item.ItemIndex?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •