protected void rptSessions_OnItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        msSessionTimeSlot ts = (msSessionTimeSlot)e.Item.DataItem;

        if (Page.IsPostBack)
        {
            return;                             // only do this if there's a postback - otherwise, preserve ViewState
        }
        switch (e.Item.ItemType)
        {
        case ListItemType.Header:
            break;

        case ListItemType.Footer:
            break;

        case ListItemType.AlternatingItem:
            goto case ListItemType.Item;

        case ListItemType.Item:
            Label    lblTimeSlot = (Label)e.Item.FindControl("lblTimeSlot");
            GridView gvSessions  = (GridView)e.Item.FindControl("gvSessions");

            lblTimeSlot.Text = ts.Name;

            // now, let's find all of the sessions
            var sessions = manifest.Sessions.FindAll(x => x.TimeSlotID == ts.ID);
            if (sessions.Count == 0)      // there are no sessions!
            {
                e.Item.Visible = false;
                return;
            }

            if (ts.ID != null && !ts.AllowMultipleSessions &&

                // MSIV-114
                sessions.Any(x => x.RegistrationMode != EventRegistrationMode.Ticketed)
                )        // we need to add a "Do Not Select" options
            {
                sessions.Insert(0, new EventManifestSession
                {
                    SessionName      = "No session selected during this time slot.",
                    RegistrationMode = EventRegistrationMode.Normal,
                    TimeSlotID       = ts.ID
                });
            }

            gvSessions.DataSource = sessions;
            gvSessions.DataBind();

            if (sessions.Count > 0)
            {
                pnlSessions.Visible = true;
            }

            break;
        }
    }
    protected void gvSessions_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        EventManifestSession session = (EventManifestSession)e.Row.DataItem;

        if (Page.IsPostBack)
        {
            return; // only do this if there's a postback - otherwise, preserve ViewState
        }
        switch (e.Row.RowType)
        {
        case DataControlRowType.Header:
            break;

        case DataControlRowType.Footer:
            break;



        case DataControlRowType.DataRow:
            msSessionTimeSlot timeSlot              = timeslots.Where(x => x.ID == session.TimeSlotID).FirstOrDefault();
            CheckBox          cbRegister            = (CheckBox)e.Row.FindControl("cbRegister");
            TextBox           tbQuantity            = (TextBox)e.Row.FindControl("tbQuantity");
            RadioButton       rbRegister            = (RadioButton)e.Row.FindControl("rbRegister");
            DropDownList      ddlFee                = (DropDownList)e.Row.FindControl("ddlFee");
            Label             lblPrice              = (Label)e.Row.FindControl("lblPrice");
            RadToolTip        rtpSessionDescription = (RadToolTip)e.Row.FindControl("rtpSessionDescription");
            Label             lblSessionName        = (Label)e.Row.FindControl("lblSessionName");

            lblSessionName.Text         = session.SessionName;
            rtpSessionDescription.Title = session.SessionName;
            rtpSessionDescription.Text  = session.SessionDescription;

            if (session.RegistrationMode == EventRegistrationMode.Ticketed)
            {
                tbQuantity.Visible = true;
            }
            else
            if (session.TimeSlotID == null || (timeSlot != null && timeSlot.AllowMultipleSessions))
            {
                // use checkboxes
                cbRegister.Visible = true;
                rbRegister.Visible = false;
            }
            else
            {
                rbRegister.Visible = true;
                rbRegister.Checked = session.SessionID == null;         // select the "do not register" option by default
                string groupName = Formats.GetSafeFieldName(session.TimeSlotID);

                // hack to work around ASP.NET RadioButtons in repeater controls bug
                // http://www.codeguru.com/csharp/csharp/cs_controls/custom/article.php/c12371/
                rbRegister.GroupName = groupName;
                string script = string.Format(
                    "SetUniqueRadioButton('gvSessions.*{0}',this)", groupName);
                rbRegister.Attributes.Add("onclick", script);

                cbRegister.Visible = false;
            }

            if (session.Fees != null)
            {
                // MS-1587 - add where filter
                // MS-5481 - only show session fees that are flagged to be sold online
                foreach (var fee in session.Fees.Where(x => x.IsEligible && x.SellOnline))
                {
                    // let's show the fee w/o the session name
                    string name = string.Format("{0} - {1}", fee.ProductName.Replace(session.SessionName + " - ", "")
                                                ,
                                                !string.IsNullOrWhiteSpace(fee.DisplayPriceAs) ? fee.DisplayPriceAs : fee.Price.ToString("C"));
                    ddlFee.Items.Add(new ListItem(name, fee.ProductID));
                }

                if (session.DefaultFee != null)
                {
                    ddlFee.SelectedValue = session.DefaultFee;
                }

                if (ddlFee.Items.Count == 1)     // just show the dang label
                {
                    ddlFee.Visible   = false;
                    lblPrice.Visible = true;

                    //MS-1587
                    //Since there's one item in the list there must be one fee where IsEligible == true
                    // MS-5481 - only show session fees that are flagged to be sold online
                    EventRegistrationProductInfo erpi = session.Fees.Single(x => x.IsEligible && x.SellOnline);

                    lblPrice.Text = !string.IsNullOrWhiteSpace(erpi.DisplayPriceAs) ? erpi.DisplayPriceAs : erpi.Price.ToString("C");
                }

                // MS-5023 If all session fees are ineligible, then hide drop-down box,
                // disable the session row and show wording with explanations
                if (ddlFee.Items.Count == 0)
                {
                    ddlFee.Visible   = false;
                    lblPrice.Visible = true;
                    lblPrice.Text    = "No eligible fees";
                    e.Row.Enabled    = false;
                }
            }
            else
            {
                ddlFee.Visible   = false;
                lblPrice.Visible = false;
            }

            if (session.Ineligible)       // can't select this
            {
                rbRegister.Enabled = cbRegister.Enabled = tbQuantity.Enabled
                                                              = ddlFee.Enabled = false;
                ddlFee.Visible   = false;
                lblPrice.Visible = true;
                lblPrice.Text    = "INELIGIBLE";
            }

            // If this is a Registration Edit, reactivate the selected Sessions and select them
            if (targetRegistration != null)
            {
                bool highlightRow = false;
                if (session.SessionID == null)
                {
                    // For "No Selection" uncheck if there is a selected session
                    var sessionList = ((GridView)sender).DataSource as List <EventManifestSession>;
                    foreach (var sessionManifest in sessionList)
                    {
                        var sessionReg = currentSessions.Select("Event = '" + sessionManifest.SessionID + "'");
                        if (sessionReg.Length > 0)
                        {
                            rbRegister.Checked = false;
                            break;
                        }
                    }

                    // If we leave selected, highlight it
                    highlightRow = rbRegister.Checked;
                }
                else
                {
                    var sessionReg = currentSessions.Select("Event = '" + session.SessionID + "'");
                    if (sessionReg.Length > 0)
                    {
                        // Hide the Fee \ Price info
                        lblPrice.Visible = true;
                        var price = sessionReg[0]["Price"] as decimal?;
                        if (price.HasValue)
                        {
                            lblPrice.Text = string.Format("{0:C}", price.Value);
                        }

                        // Make sure that the line has a Product ID
                        ddlFee.Visible = false;
                        if (ddlFee.Items.Count == 0)
                        {
                            ddlFee.Items.Add(Convert.ToString(sessionReg[0]["Fee"]));
                        }

                        // Make sure row is enabled
                        e.Row.Enabled = true;

                        // Select this row
                        if (session.RegistrationMode == EventRegistrationMode.Ticketed)
                        {
                            tbQuantity.Text = sessionReg.Length.ToString();
                        }
                        else if (session.TimeSlotID == null || (timeSlot != null && timeSlot.AllowMultipleSessions))
                        {
                            cbRegister.Checked = true;
                        }
                        else
                        {
                            rbRegister.Checked = true;
                        }

                        // Hightlight the row
                        highlightRow = true;
                    }
                }

                if (highlightRow)
                {
                    e.Row.CssClass = "hlte";

                    var altStyle = ((GridView)sender).AlternatingRowStyle.CssClass;
                    if (!string.IsNullOrEmpty(altStyle) && e.Row.RowIndex % 2 == 1)
                    {
                        e.Row.CssClass += " " + altStyle;
                    }
                }
            }

            break;
        }
    }