using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MyTunes
{
    public partial class WebForm3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtArtistBLLFilter.Text))
                MyTunesBLL.FilterExpression = "artist LIKE '%" + txtArtistBLLFilter.Text + "%'";
        }

        protected void btnArtistBLLFilterGo_Click(object sender, ImageClickEventArgs e)
        {
            if (!string.IsNullOrEmpty(txtArtistBLLFilter.Text))
                MyTunesBLL.FilterExpression = "artist LIKE '%" + txtArtistBLLFilter.Text + "%'";
            else
                MyTunesBLL.FilterExpression = null;

            ArtistBLLGridView.DataBind();

        }

        protected void txtArtistBLLFilter_TextChanged(object sender, EventArgs e)
        {
            btnArtistBLLFilterGo_Click(null, null);
        }

        protected void ArtistBLLGridView_DataBound(object sender, EventArgs e)
        {
            lblBLLPageInfo.Text = string.Format("You are viewing page {0} of {1}...",
                ArtistBLLGridView.PageIndex + 1, ArtistBLLGridView.PageCount);

            lstPageSelectBLL.Items.Clear();
            for (int i = 0; i < ArtistBLLGridView.PageCount; i++)
            {
                ListItem pageItem = new ListItem(string.Concat("Page ", i + 1), i.ToString());
                lstPageSelectBLL.Items.Add(pageItem);
                if (i == ArtistBLLGridView.PageIndex)
                    pageItem.Selected = true;
            }
        }

        protected void lstPageSelectBLL_SelectedIndexChanged(object sender, EventArgs e)
        {
            ArtistBLLGridView.PageIndex = Convert.ToInt32(lstPageSelectBLL.SelectedValue);
        }
    }
}