T
Teej
Good afternoon,
General goal:
I am working on a Web application (C#) in which the first screen is
simple enough: it displays a DataGrid based on data from a SQL Server
database. One of the columns in the db is a DateTime column, which of
course has the date and time displayed in each record. In the
DataGrid, I only want the date, and not the time, displayed for each
record, which I am successfully able to do by parsing out the date
portion of the record in the ItemDataBound event handler. This is also
a sortable column, but I haven't yet implemented any sort code in the
code-behind; all I did was put an empty sort method in.
Problem(s):
As mentioned, I can get the date parsed out correctly, but at the same
time, the column header for this column is blank. If I clicked on any
of the other sortable column headers, the column header in question
appears after the postback. Here is a little bit of code from the
ItemDataBound event handler and some things I noticed through
trialing-and-erroring (with "Created" being the column header text):
if (e.Item.Cells[1].Text != "Created")
{
string createdDate = e.Item.Cells[1].Text.ToString();
e.Item.Cells[1].Text = createdDate.Substring(0, createdDate.IndexOf("
") + 1);
}
1. If I comment out the above code, the date is obviously displayed in
full form, and the column header is displayed, BUT not sortable.
2. If I remove the SortExpression attribute from the HTML portion, the
column header is displayed and the date is truncated correctly, but
obviously not sortable.
As I'm typing this, I am realizing there appears to be some kind of
connection between the header not being displayed and the
SortExpression attribute existing. I will keep researching, but does
anyone have any more insight on this, or might someone be able to
suggest any more steps I could take toward solving this? If so, I
would greatly appreciate it. Thanks for your consideration!
Sincerely,
Tim
General goal:
I am working on a Web application (C#) in which the first screen is
simple enough: it displays a DataGrid based on data from a SQL Server
database. One of the columns in the db is a DateTime column, which of
course has the date and time displayed in each record. In the
DataGrid, I only want the date, and not the time, displayed for each
record, which I am successfully able to do by parsing out the date
portion of the record in the ItemDataBound event handler. This is also
a sortable column, but I haven't yet implemented any sort code in the
code-behind; all I did was put an empty sort method in.
Problem(s):
As mentioned, I can get the date parsed out correctly, but at the same
time, the column header for this column is blank. If I clicked on any
of the other sortable column headers, the column header in question
appears after the postback. Here is a little bit of code from the
ItemDataBound event handler and some things I noticed through
trialing-and-erroring (with "Created" being the column header text):
if (e.Item.Cells[1].Text != "Created")
{
string createdDate = e.Item.Cells[1].Text.ToString();
e.Item.Cells[1].Text = createdDate.Substring(0, createdDate.IndexOf("
") + 1);
}
1. If I comment out the above code, the date is obviously displayed in
full form, and the column header is displayed, BUT not sortable.
2. If I remove the SortExpression attribute from the HTML portion, the
column header is displayed and the date is truncated correctly, but
obviously not sortable.
As I'm typing this, I am realizing there appears to be some kind of
connection between the header not being displayed and the
SortExpression attribute existing. I will keep researching, but does
anyone have any more insight on this, or might someone be able to
suggest any more steps I could take toward solving this? If so, I
would greatly appreciate it. Thanks for your consideration!
Sincerely,
Tim