我试图根据我为 gridview 设置的某些条件禁用 gridview 中的所有行,如文本框和下拉控件。我现在有它,它可以改变颜色,但我也想锁定它或禁用那些控件,我该怎么做?
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblEndDate = (Label)e.Row.FindControl("lblStudyEndDate");
DateTime EndDate = DateTime.Parse(lblEndDate.Text);
if (EndDate < DateTime.Today)
{
//make all rows to read only here..
}
}
}
最佳答案
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblEndDate = (Label)e.Row.FindControl("lblStudyEndDate");
TextBox tbSomeTB = e.Row.FindControl("tbSomeTB") as TextBox;
DateTime EndDate = DateTime.Parse(lblEndDate.Text);
if (EndDate < DateTime.Today)
{
e.Row.BackColor = System.Drawing.Color.DarkGray;
tbSomeTB.Enabled = false;
}
}
}
很直接,评论里的人已经说过了,这是你显然已经知道如何编写的代码。
关于c# - asp.net 如何禁用 gridview 中的所有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30490199/