就是在点击datagrid 某行的“编辑”按钮后,该行所有的列都会变成textbox供修改。
而我想让其中某一列的textbox不可修改,(可能比如设enabled或者readonly什么的值)同时,因为这个要在“满足特殊条件A”时才不能修改,不满足时要还是能修改的。所以也不能在前台直接把这列设为不能修改。请教各位大大这个怎么实现~~谢谢~~我自己按下面这样写的,但总是报对象未引用到实例TextBox txt=new TextBox ();
if(满足特殊条件A)
{
     txt=(TextBox)e.Item.FindControl("TxtPlanQty"); 
     txt.Enabled =false;
}

解决方案 »

  1.   

    TextBox txt=new TextBox ();
    TextBox txt;
      

  2.   


    你是指用TextBox txt;代替TextBox txt=new TextBox ();吗?
    试了下,好像还是不行。
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.Source Error: 
    Line 1055:
    Line 1056: txt=(TextBox)e.Item.FindControl("TxtPlanQty"); 
    Line 1057: txt.Enabled   =false;
    Line 1058:
    Line 1059:
     
      

  3.   

    TextBox txt=(TextBox)e.Item.FindControl("TxtPlanQty");  
      

  4.   

    TextBox deletebutton=(TextBox )datagrid1.rows[i].findcontrol(’TxtPlanQty‘);
      

  5.   

    Enable="<# GetEnable(Eval(""))%>"
    public bool GetEnable(object o)
    {
    //
    return false;
    }
      

  6.   


    我加了这两个以后在private void datagrid1_EditCommand里怎么写~?if(满足特殊条件A)
    {
        这里怎么写
    }
      

  7.   

    你这个明显就是没能找到那个TextBox
      

  8.   

    aspx
    Enable="<# GetEnable(Eval("字段"))%>" //TextBox的Enable属性aspx.cs
    public bool GetEnable(object o)
    {
    //
    return 是否满足条件A;
    }
      

  9.   

    Enable='<# GetEnable(Eval("字段"))%>' //TextBox的Enable属性
      

  10.   

    字段是指什么 datagrid绑定的表里的?
    我aspx是、
    <EditItemTemplate>
    <asp:TextBox ID="TxtPlanQty" runat="server" Enabled='<%# GetEnable(Eval("DataItem.Plan_Quantity"))%>' Text='<%# DataBinder.Eval(Container, "DataItem.Plan_Quantity") %>'>
    </asp:TextBox>
    </EditItemTemplate>
    cs加了
    public bool GetEnable(object o)
    {
    if(满足特殊条件A)
    {//
    return false;
    }
    else
    {
    return true;
    }
    }
    这样对吗?
      

  11.   

    额 ok了
    Enabled='<%# GetEnable(Eval("DataItem.Plan_Quantity"))%>' 
    我这样写没有eval
    后来改成
    Enabled='<%# GetEnable("随便写")%>' 
    就ok了~~
    总之,谢谢大家~~~