[英]how to disable all rows in gridview in asp.net
我试图根据我为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;
}
}
}
很简单,评论中的人已经说过,这里是你已经清楚知道如何编写的代码。
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblEndDate = (Label)e.Row.FindControl("lblStudyEndDate");
TextBox txt_1 = (TextBox)e.Row.FindControl("txt_1");
DropDownList ddl_1 = (DropDownList)e.Row.FindControl("DropDownList1");
DateTime EndDate = DateTime.Parse(lblEndDate.Text);
if (EndDate < DateTime.Today)
{
txt_1.Enabled = false;
ddl_1.Enabled = false;
e.Row.CssClass = "setColorClass"; // css class to set bgcolor , forecolor etc
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.