我试图根据我为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..
}
}
}
答案 0 :(得分:2)
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;
}
}
}
非常直截了当,评论中的人已经说过,这里是你已经清楚知道如何写的代码。
答案 1 :(得分:1)
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
}
}
}