for (int i = 0; i < DataList1.Items.Count; i++)
                {
                    //DataList1.Items[i].FindControl("TextBox1").ReadOnly=true;
                }这样不行啊。每天都问问题。。

解决方案 »

  1.   

    在datalist的RowDataBound事件里
    通过遍历找到你的textbox然后附件属性我只有gridview里将checkbox设置为选择 和 不可操作的protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    e.Row.Attributes.Add("onmouseover", "javascript:this.className='hover'");
                    e.Row.Attributes.Add("onmouseout", "javascript:this.className='normal'");
                    ((CheckBox)e.Row.FindControl("checkbox控件ID")).Checked = true;
                    ((CheckBox)e.Row.FindControl("checkbox控件ID")).Enabled = false;
                }
            }
      

  2.   

    for (int i = 0; i < DataList1.Items.Count; i++)
      {
      //DataList1.Items[i].FindControl("TextBox1").ReadOnly=true;
      }
    你这样设置有什么意义呢?如果你要设置初始状态为只读 就可以在他的属性里面设置啊