1

Hey guys i need some help with my GridView, i just started this asp.net thing and i´m not sure if this is even possible.

so here is my Problem:

I have a GridView with "DateTime" Objects.

            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();

This is how i add my first row and until this Point, it works fine. So what i did on my other Gridviews is to get always the current data, if the page is loaded.

    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;


    }

But now i cant get my DateTime Object back from the GridView, is there anyway i can get it? this stuff worked with strings, but now i cant find the answer how to get my Object.

1 Answer 1

2

Instead of this

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

Use Below code

table.Rows[row.RowIndex][i] = row.Cells[i].Text;
Sign up to request clarification or add additional context in comments.

1 Comment

Wow, i dont know why, but it works now! i used this yesterday and i did not work.. suddenly it does... mindblow^^

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.