示例#1
0
        protected void MakeTable(List <IBook> books)
        {
            int x = 1;

            Table1.Rows.Clear();
            TableHeaderRow thr = new TableHeaderRow();

            TableHeaderCell thc1 = new TableHeaderCell();

            thc1.Text = "NUM";

            TableHeaderCell thc2 = new TableHeaderCell();

            thc2.Text = "ID";

            TableHeaderCell thc3 = new TableHeaderCell();

            thc3.Text = "NAME";

            TableHeaderCell thc4 = new TableHeaderCell();

            thc4.Text = "AUTHOR";

            TableHeaderCell thc5 = new TableHeaderCell();

            thc5.Text = "YEAR";

            TableHeaderCell thc6 = new TableHeaderCell();

            thc6.Text = "PRICE";

            TableHeaderCell thc7 = new TableHeaderCell();

            thc7.Text = "FLOAT";

            thr.Cells.Add(thc1);
            thr.Cells.Add(thc2);
            thr.Cells.Add(thc3);
            thr.Cells.Add(thc4);
            thr.Cells.Add(thc5);
            thr.Cells.Add(thc6);
            thr.Cells.Add(thc7);

            Table1.Rows.Add(thr);
            for (int i = 0; i < books.Count; i++)
            {
                IBook book = books[i];
                System.Diagnostics.Debug.Write(book);
                TableRow tr = new TableRow();

                TableCell tc1 = new TableCell();
                tc1.Text = Convert.ToString(x);
                x       += 1;

                TableCell tc2 = new TableCell();
                tc2.Text = book.ID;

                TableCell tc3 = new TableCell();
                tc3.Text = book.Name;
                System.Diagnostics.Debug.Write(book.Name);

                TableCell tc4 = new TableCell();
                tc4.Text = book.Author;

                TableCell tc5 = new TableCell();
                tc5.Text = Convert.ToString(book.Year);

                TableCell tc6 = new TableCell();
                tc6.Text = Convert.ToString(book.Price);

                TableCell tc7 = new TableCell();
                tc7.Text = Convert.ToString(book.Stock);

                tr.Cells.Add(tc1);
                tr.Cells.Add(tc2);
                tr.Cells.Add(tc3);
                tr.Cells.Add(tc4);
                tr.Cells.Add(tc5);
                tr.Cells.Add(tc6);
                tr.Cells.Add(tc7);
                Table1.Rows.Add(tr);
            }
        }