Esempio n. 1
0
 private void PopulateDogGridView(List <Dogs> dogList)
 {
     DogGridView.DataSource = dogList;
     DogGridView.DataBind();
 }
Esempio n. 2
0
    private void PopulateDogGridView(List <Dogs> tblDogs, int pageNo)
    {
        if (tblDogs == null)
        {
            tblDogs = Common.Dog_GridViewData;
        }
        List <Dogs> newDogs = new List <Dogs>();

        int itemsperPage  = Int32.Parse(WebConfigurationManager.AppSettings["GridItemsPerPage"]);
        int startRowIndex = (pageNo - 1) * itemsperPage;
        int currentIndex  = 0;
        int itemsRead     = 0;
        int totalRecords  = tblDogs.Count;

        foreach (Dogs row in tblDogs)
        {
            if (itemsRead < itemsperPage && currentIndex < totalRecords && currentIndex >= startRowIndex)
            {
                Dogs newDog = new Dogs(_connString);
                newDog.Dog_ID       = row.Dog_ID;
                newDog.Dog_KC_Name  = row.Dog_KC_Name;
                newDog.Dog_Pet_Name = row.Dog_Pet_Name;
                if (!row.IsReg_NoNull)
                {
                    newDog.Reg_No = row.Reg_No;
                }
                DogBreeds dogBreeds = new DogBreeds(_connString, Convert.ToInt32(row.Dog_Breed_ID));
                newDog.Dog_Breed_Description = dogBreeds.Description;
                DogGender dogGender = new DogGender(_connString, Convert.ToInt32(row.Dog_Gender_ID));
                newDog.Dog_Gender = dogGender.Description;
                newDogs.Add(newDog);
                itemsRead++;
            }
            currentIndex++;
        }
        lblTotalPages.Text = CalculateTotalPages(totalRecords).ToString();

        lblCurrentPage.Text = CurrentPage.ToString();

        if (CurrentPage == 1)
        {
            Btn_Previous.Enabled = false;

            if (Int32.Parse(lblTotalPages.Text) > 0)
            {
                Btn_Next.Enabled = true;
            }
            else
            {
                Btn_Next.Enabled = false;
            }
        }

        else
        {
            Btn_Previous.Enabled = true;

            if (CurrentPage == Int32.Parse(lblTotalPages.Text))
            {
                Btn_Next.Enabled = false;
            }
            else
            {
                Btn_Next.Enabled = true;
            }
        }
        DogGridView.DataSource = newDogs;
        DogGridView.DataBind();
    }