syntax error in c# using repeaters

Posted on 2008-11-18
Last Modified: 2013-12-17
I have a repeater in my code which gets all the events in a particular month and then using the dates found in the database I have a nested repeater to search for all events in that date, then a further nested repeater searches to see if the events found have a value in a particular field.
I think its nearly working but i'm stuck with the syntax on the second repeater.

 foreach (RepeaterItem repeaterID in Repeaterday.Items)

i have an error that Repeaterday does not exist in the current context

I'm not sure what to change it to, i tried Dataset.Items which it doesnt like either

Please help!
protected void Page_Load(object sender, EventArgs e)


        object result = null;

        string monthID = Request["Month"];

        Monthfixtureslabel.Text = "Fixtures for " + monthID;


        SqlCommand mySqlSelectMonth = new SqlCommand("exec usp_GetAllMonthFixtures @monthID", conn);

        mySqlSelectMonth.Parameters.Add("MonthID", SqlDbType.NVarChar);

        mySqlSelectMonth.Parameters["MonthID"].Value = monthID;

        mySqlSelectMonth.CommandType = CommandType.Text;

        SqlDataAdapter mySqlAdapterMonth = new SqlDataAdapter(mySqlSelectMonth); 


        DataSet MonthDataSet = new DataSet();


        RepeaterMonth.DataSource = MonthDataSet;


        int k = 0;

        foreach (RepeaterItem repeaterItem in RepeaterMonth.Items)


            string date = MonthDataSet.Tables[0].Rows[k]["Date"].ToString();



                SqlCommand mySqlSelect = new SqlCommand("exec usp_GetTestMonthFixtures @monthID, @Date", conn);

                mySqlSelect.Parameters.Add("MonthID", SqlDbType.NVarChar);

                mySqlSelect.Parameters["MonthID"].Value = monthID;

                mySqlSelect.Parameters.Add("Date", SqlDbType.NVarChar);

                mySqlSelect.Parameters["Date"].Value = date;

                mySqlSelect.CommandType = CommandType.Text;

                SqlDataAdapter mySqlAdapter = new SqlDataAdapter(mySqlSelect); 


                DataSet DataSet = new DataSet();


                ((Repeater)(repeaterItem.FindControl("Repeaterday"))).DataSource = DataSet;


                int l = 0;

                foreach (RepeaterItem repeaterID in Repeaterday.Items)


                    Guid tempID = (Guid) MonthDataSet.Tables[0].Rows[l]["ID"];



                        SqlCommand mySqlSelectAM = new SqlCommand("exec usp_GetMonthAllAMFixtures @ID", conn);

                        mySqlSelectAM.Parameters.Add("ID", SqlDbType.UniqueIdentifier);

                        mySqlSelectAM.Parameters["ID"].Value = tempID;

                        mySqlSelectAM.CommandType = CommandType.Text;

                        SqlDataAdapter mySqlAdapterAM = new SqlDataAdapter(mySqlSelectAM);

                        DataSet AMDataSet = new DataSet();


                        if (AMDataSet.Tables[0].Rows.Count <= 0)


                            AMDataSet.Tables[0].Rows.Add(new object[] { "No events", "" });


                        ((Repeater)(repeaterItem.FindControl("RepeaterAM"))).DataSource = AMDataSet;




                        SqlCommand mySqlSelectPM = new SqlCommand("exec usp_GetMonthAllPMFixtures @ID", conn);

                        mySqlSelectPM.Parameters.Add("ID", SqlDbType.NVarChar);

                        mySqlSelectPM.Parameters["ID"].Value = tempID;

                        mySqlSelectPM.CommandType = CommandType.Text;

                        SqlDataAdapter mySqlAdapterPM = new SqlDataAdapter(mySqlSelectPM);

                        DataSet PMDataSet = new DataSet();


                        if (PMDataSet.Tables[0].Rows.Count <= 0)


                            PMDataSet.Tables[0].Rows.Add(new object[] { "No events", "" });


                        ((Repeater)(repeaterItem.FindControl("RepeaterPM"))).DataSource = PMDataSet;




                        SqlCommand mySqlSelectClub = new SqlCommand("exec usp_GetMonthAllClubFixtures @ID", conn);

                        mySqlSelectClub.Parameters.Add("ID", SqlDbType.NVarChar);

                        mySqlSelectClub.Parameters["ID"].Value = tempID;

                        mySqlSelectClub.CommandType = CommandType.Text;

                        SqlDataAdapter mySqlAdapterClub = new SqlDataAdapter(mySqlSelectClub);

                        DataSet ClubDataSet = new DataSet();


                        if (ClubDataSet.Tables[0].Rows.Count <= 0)


                            ClubDataSet.Tables[0].Rows.Add(new object[] { "No events", "" });


                        ((Repeater)(repeaterItem.FindControl("RepeaterClub"))).DataSource = ClubDataSet;











Open in new window

Question by:CharlieDev
    LVL 14

    Accepted Solution

    I see you access RepeaterDay   through the FindControl method above your call to your foreach loop.     I would say you have two options.

    First is you could change your foreach loop to use ((Repeater)(repeaterItem.FindControl("Repeaterday"))).Items

    Create a variable for Repeater day,   set it equal to (Repeater)(repeaterItem.FindControl("Repeaterday")  
    then update your foreach loop to that new variable.items.

    Author Comment

    Great thanks :)

    Author Closing Comment

    cheers :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now