这种情况应该在EditItemTemplate中定义处理编辑状态下的各个控件的类型(如TextBox, CheckBox等),赋予其一个唯一的ID。 然后在ItemDataBound过程中控件这些控件的属性。ms-help://MS.VSCC/MS.MSDNQTR.2003JAN.1033/Cpqstart/html/cpsmpnetsamples-aspnetdataaccess.htm

解决方案 »

  1.   

    to:spring_ok
    你有没有试过这种方法,我这样使用不行,会出现找不到该controls的实例错误,能否提供一份例子代码。
    底下为我的代码:
    //------------索引值越界错误-----------------
    ((TextBox)e.Item.Cells[1].Controls[0]).Width = 10;
    ((TextBox)e.Item.Cells[1].Controls[0]).ReadOnly = true;
    //------------------------------------------------
    //------------没有引入实例错误------------------
    ((TextBox)e.Item.Cells[1].FindControl("ID").Width = 10;
    ((TextBox)e.Item.Cells[1].FindControl("ID").ReadOnly = true;
    //----------------------------------------------
      

  2.   

    配置GridColumnStyles,以下是部分代码:GridTableStyle.GridColumnStyles[i].ReadOnly=true; GridTableStyle.GridColumnStyles[i].MappingName=FieldName;
    GridTableStyle.GridColumnStyles[i].HeaderText=FieldName_CH;
    GridTableStyle.GridColumnStyles[i].Alignment=HorizontalAlignment.Left;
    GridTableStyle.GridColumnStyles[i].Width=20;具体文档可以参考MSDN。
      

  3.   

    to:wljcan
    上段代码写在什么位置,GridTableStyle是从哪来的,是谁的属性?
      

  4.   

    现公布解决的办法:关键的代码在DataGrid1_EditCommand 函数中:                        DataGrid1.EditItemIndex = e.Item.ItemIndex;                        DataGrid1.DataBind();                        DataGridItem dgItem;                        TextBox box0;                        TextBox box1;                        dgItem=DataGrid1.Items[e.Item.ItemIndex];                        box0 = (TextBox)(dgItem.Cells[0].Controls[0]);                        box1 = (TextBox)(dgItem.Cells[1].Controls[0]);                                        box0.Width=100;                        box0.Height=20;                        box0.BackColor=System.Drawing.Color.Blue;                        box0.ReadOnly=true;                         box1.Width=100;                        box1.Height=20;                        box1.BackColor=System.Drawing.Color.Green;                        box1.ReadOnly=false;