asp.net 带有对象的网格视图

asp.net Gridview with objects

大家好,我的 GridView 需要一些帮助,我刚刚开始这个 asp.net 事情,我不确定这是否可能。

所以这是我的问题:

我有一个带有 "DateTime" 个对象的 GridView。

            DataTable Timetable = new DataTable();

            Timetable.Columns.Add("From", typeof(DateTime));
            Timetable.Columns.Add("To", typeof(DateTime));

            DataRow dr = Timetable.NewRow();

            dr[0] = Convert.ToDateTime(TextBox_TFrom.Text);
            dr[1] = Convert.ToDateTime(TextBox_TTo.Text);

            Timetable.Rows.Add(dr);

            trainingTimes.DataSource = Timetable;
            trainingTimes.DataBind();

这就是我添加第一行的方式,直到此时,它工作正常。 所以我在我的其他 Gridview 上所做的是始终获取当前数据,如果页面已加载。

    public DataTable currentTimeGridView()
    {


        DataTable table = new DataTable();

        foreach (TableCell cell in trainingTimes.HeaderRow.Cells)
        {


            table.Columns.Add(cell.Text);

        }

        foreach (GridViewRow row in trainingTimes.Rows)
        {

            table.Rows.Add();

            for (int i = 0; i < row.Cells.Count; i++)
            {

                Label4.Text = trainingTimes.Columns.ToString();

                table.Rows[row.RowIndex][i] = row.Cells[i];

            }


        }


        return table;


    }

但是现在我无法从 GridView 取回我的 DateTime 对象,我是否可以获取它?这些东西适用于字符串,但现在我找不到如何获取我的对象的答案。

而不是这个

  table.Rows[row.RowIndex][i] = row.Cells[i]

使用下面的代码

table.Rows[row.RowIndex][i] = row.Cells[i].Text;