Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 462
  • Last Modified:

syntax error in c# using repeaters

Hi,
I have a repeater in my asp.net 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!
Thanks
protected void Page_Load(object sender, EventArgs e)
    {
        object result = null;
        string monthID = Request["Month"];
 
        Monthfixtureslabel.Text = "Fixtures for " + monthID;
 
        OpenConnection();
 
        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();
 
        mySqlAdapterMonth.Fill(MonthDataSet);
 
        RepeaterMonth.DataSource = MonthDataSet;
 
        RepeaterMonth.DataBind();
 
        int k = 0;
 
        foreach (RepeaterItem repeaterItem in RepeaterMonth.Items)
        {
            string date = MonthDataSet.Tables[0].Rows[k]["Date"].ToString();
 
            OpenConnection();
            {
                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();
 
                mySqlAdapter.Fill(DataSet);
 
                ((Repeater)(repeaterItem.FindControl("Repeaterday"))).DataSource = DataSet;
 
                ((Repeater)(repeaterItem.FindControl("Repeaterday"))).DataBind();
 
                int l = 0;
 
                foreach (RepeaterItem repeaterID in Repeaterday.Items)
                {
                    Guid tempID = (Guid) MonthDataSet.Tables[0].Rows[l]["ID"];
 
                    OpenConnection();
                    {
                        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();
 
                        mySqlAdapterAM.Fill(AMDataSet);
 
                        if (AMDataSet.Tables[0].Rows.Count <= 0)
                        {
                            AMDataSet.Tables[0].Rows.Add(new object[] { "No events", "" });
                        }
 
                        ((Repeater)(repeaterItem.FindControl("RepeaterAM"))).DataSource = AMDataSet;
 
                        ((Repeater)(repeaterItem.FindControl("RepeaterAM"))).DataBind();
 
                    }
 
                    {
                        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();
 
                        mySqlAdapterPM.Fill(PMDataSet);
 
                        if (PMDataSet.Tables[0].Rows.Count <= 0)
                        {
                            PMDataSet.Tables[0].Rows.Add(new object[] { "No events", "" });
                        }
 
                        ((Repeater)(repeaterItem.FindControl("RepeaterPM"))).DataSource = PMDataSet;
 
                        ((Repeater)(repeaterItem.FindControl("RepeaterPM"))).DataBind();
 
                    }
                    {
                        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();
 
                        mySqlAdapterClub.Fill(ClubDataSet);
 
                        if (ClubDataSet.Tables[0].Rows.Count <= 0)
                        {
                            ClubDataSet.Tables[0].Rows.Add(new object[] { "No events", "" });
                        }
 
                        ((Repeater)(repeaterItem.FindControl("RepeaterClub"))).DataSource = ClubDataSet;
 
                        ((Repeater)(repeaterItem.FindControl("RepeaterClub"))).DataBind();
 
                    }
                    CloseConnection();
 
                    l++;
 
 
                }
 
                CloseConnection();
 
                k++;
            }
        }
    }

Open in new window

0
CharlieDev
Asked:
CharlieDev
  • 2
1 Solution
 
jjardineCommented:
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

Or
Create a variable for Repeater day,   set it equal to (Repeater)(repeaterItem.FindControl("Repeaterday")  
then update your foreach loop to that new variable.items.
0
 
CharlieDevAuthor Commented:
Great thanks :)
0
 
CharlieDevAuthor Commented:
cheers :)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now