默认的TextBox太宽了,我用下面的程序改变其宽度不知道是哪里写错了,小弟我刚接触ASP.NET,麻烦大家多多指教  .分虽然少点但是希望大家不要嫌弃.  
 
void  UserList_EditCommand(object  sender,  DataGridCommandEventArgs  e)  {  
       UserList.EditItemIndex=e.Item.ItemIndex;  
       LoadGrid();  
       TextBox  curText;  
       for(int  i=0;i<UserList.Columns.Count;i++)  
         {  
 
         if(UserList.Items[e.Item.ItemIndex].Cells[i].Controls[0].GetType().ToString()=="System.Web.UI.WebControls.TextBox")  
               {  
                   curText=(TextBox)UserList.Items[e.Item.ItemIndex].Cells[i].Controls[0];  
                   curText.Width=100;  
               }  
         }  
       }  
错误信息如下:
  
Specified  argument  was  out  of  the  range  of  valid  values.  Parameter  name:  index    
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.ArgumentOutOfRangeException:  Specified  argument  was  out  of  the  range  of  valid  values.  Parameter  name:  index  
 
Source  Error:    
 
 
Line  82:            {  
Line  83:    
Line  84:            if(UserList.Items[e.Item.ItemIndex].Cells[i].Controls[0].GetType().ToString()=="System.Web.UI.WebControls.TextBox")  
Line  85:                  {  
Line  86:                      curText=(TextBox)UserList.Items[e.Item.ItemIndex].Cells[i].Controls[0];  
   
Source File: F:\IIS\design\usermanage.aspx    Line: 84  

解决方案 »

  1.   

    在ItemDataBound中if(e.Item.ItemType=ListItemType.EditItem){找到那个TextBox}
      

  2.   

    VB.NET寫法:
            DataGrid1.Columns(0).ItemStyle.Width.Pixel(100)
            DataGrid1.Columns(1).ItemStyle.Width.Pixel(100)
    我是把它們放在datagrid1.databind()之後
      

  3.   

    Sorry,上面的是修改查詢的欄位寬度,你的是在編輯狀態下我再找找看:)
      

  4.   

    看了你的錯誤訊息,好像是說e.Item.ItemIndex在迴圈時超出範圍
    你只用修正你編輯那一行即可,而不必要迴圈
    即只修正e.item.ItemIndex這一行即可