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.
Instead of this
table.Rows[row.RowIndex][i] = row.Cells[i]
Use Below code
table.Rows[row.RowIndex][i] = row.Cells[i].Text;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.