如何在 asp.net 中禁用 gridview 中的所有行

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 
        }
    }
}