I am currently trying to access a cell to obtain the value within it and compare it to todays date.
If the cells value is less than todays date I want to say a "Submission" is due if there has not already been one (if the cells value is the default empty Text then there is no submission).
Example Gridview:
ID SubDate Name Recieved File Comments // Column Headers 11111 | 2011/04 | - | - | - | n/a // Rows contents
Going by the example Gridview, I want to get the date in "SubDate" which is 2011/04. And compare it to todays date. Since it is less than todays date I want to replace t开发者_StackOverflow社区he "-" in the other cells with "No Submission".
My attempts so far have not worked:
DateTime today = System.DateTime.Now;
string subdate;
DateTime date = DateTime.Parse(/* Need to Get Cell Value Here*/);
subdate = date.ToShortDateString();
if (date <= today)
{
if (GridView1.EmptyDataText == "-")
{
GridView1.EmptyDataText = "No Submission";
}
}
Anyone able to help me?
Do you realy have to break in to the GridView? Consider separating your data from the UI representaion. For example you can bind to a List<Submitions>
where
public class Submition
{
public int ID { get; set; }
public DateTime date { get; set; }
public string SubmitionName { get; set; }
public string SubmitionNameView
{
get
{
if (date <= DateTime.Now && SubmitionName == "-")
return "No Submission";
else
return SubmitionName;
}
set
{
SubmitionName = value;
}
}
}
And bind your GridView columns to SubmitionNameView insted of SubmitionName;
精彩评论