无需使用 SelectedIndex 等即可获取 Gridview Cell 的值

发布于 2024-11-27 13:21:28 字数 801 浏览 1 评论 0原文

我目前正在尝试访问一个单元格以获取其中的值并将其与今天的日期进行比较。

如果单元格值小于今天的日期,我想说的是,如果还没有“提交”,则应提交(如果单元格值是默认的空文本,则没有提交)。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不忘初心 2024-12-04 13:21:28

您真的必须闯入 GridView 吗?考虑将数据与 UI 表示分离。例如,您可以绑定到 List 并将

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;
        }
    }
}

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文