无需使用 SelectedIndex 等即可获取 Gridview Cell 的值
我目前正在尝试访问一个单元格以获取其中的值并将其与今天的日期进行比较。
如果单元格值小于今天的日期,我想说的是,如果还没有“提交”,则应提交(如果单元格值是默认的空文本,则没有提交)。
Gridview 示例:
ID 子日期名称收到的文件注释 // 列标题 11111 | 11111 2011/04 | - | - | - | n/a // 行内容
以 Gridview 为例,我想获取“SubDate”中的日期,即 2011/04。并将其与今天的日期进行比较。由于它比今天的日期短,我想将其他单元格中的“-”替换为“不提交”。
到目前为止我的尝试还没有成功:
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";
}
}
有人能帮助我吗?
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 the "-" 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您真的必须闯入 GridView 吗?考虑将数据与 UI 表示分离。例如,您可以绑定到
List
并将GridView 列绑定到 SubmitionNameView 而不是 SubmitionName;
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>
whereAnd bind your GridView columns to SubmitionNameView insted of SubmitionName;