繁体   English   中英

asp.net Gridview与对象

[英]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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM