【问题标题】:Disable updates to gridview based on Date根据日期禁用对 gridview 的更新
【发布时间】:2016-06-22 07:32:56
【问题描述】:

我正在 Visual Studio 中编写一个 Web 应用程序,使用实体从 SQL Server 2012 读取数据。我需要前端或数据库中的代码,如果 periodstart 大于当前日期,则将根据当前日期(系统)检查 PeriodStart(日期字段),用户必须能够编辑它,如果不是用户一定不能做任何应该出现的消息。

谢谢

【问题讨论】:

  • 你正在尝试的任何代码
  • @NazirUllah 我正在尝试比较 PeriodStart 和系统日期作为开始,例如:IF PeriodStart > GetDate() as Current
  • 您的问题不清楚,请更新您的代码以获得更好的答案

标签: c# sql asp.net sql-server gridview


【解决方案1】:

你可以试试这个

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) {
        if (e.Row.RowType == DataControlRowType.DataRow) {
            // assuming the the ShowEditLink resides in the first column of Grid
            //just changed the index of cells to where the EditLink resides
            LinkButton lb = (LinkButton)e.Row.Cells[0].Controls[0];

            //if you are displaying the PeriodStart in the Grid using BoundField
            //Cells[1] means you are displaying the date in second column, just change the index
            //where you display the date
            DateTime periodStart = Convert.ToDateTime(e.Row.Cells[1].Text);
            if (lb != null) {
                if (periodStart > DateTime.Now)
                    lb.Visible = true;
                else
                    lb.Visible = false;
         }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-01
    • 2014-04-25
    相关资源
    最近更新 更多