Link to home
Start Free TrialLog in
Avatar of CharlieDev
CharlieDevFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of jjardine
jjardine
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CharlieDev

ASKER

Great thanks :)
cheers :)