我正在Visual Studio中编写一个Web应用程序,其中使用实体从SQL Server 2012读取数据。如果periodstart大于当前日期,我需要在前端或数据库中检查PeriodStart(Date Field)与当前日期(System)的代码,用户必须能够编辑它,如果不是用户必须无法做任何消息应该出现的事情。
由于
答案 0 :(得分:0)
你可以试试这个
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;
}
}
}