控制DataGrid在编辑状态下文本框的宽度

 1        private void dgwfl_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
 2        {
 3            if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item ) 
 4            
 5                e.Item.Attributes.Add("onmouseover""this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='#C8F7FF'"); 
 6
 7                e.Item.Attributes.Add("onmouseout""this.style.backgroundColor=this.oldcolor");
 8
 9                LinkButton delBttn = (LinkButton) e.Item.Cells[1].Controls[0]; 
10                delBttn.Attributes.Add("onclick","javascript:return confirm('确定删除此流转 - " + e.Item.Cells[6].Text + "?');"); 
11                
12                for (int i = 0; i< dgwfl.Columns.Count; i++ ) 
13                
14                    e.Item.Cells[i].Attributes.Add("onmouseover"
15                        "this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='#99ccff'"); 
16                    e.Item.Cells[i].Attributes.Add( 
17                        "onmouseout""this.style.backgroundColor=this.oldcolor"); 
18                }
 
19        
20            }

21//设置宽度
22            if (e.Item.ItemType == ListItemType.EditItem) 
23            {
24                for (int i=0;i<e.Item.Cells.Count;i++)
25                {
26                    if(e.Item.Cells[i].Controls.Count>0)
27                    {
28                        try
29                        {
30                            TextBox tb =(TextBox)e.Item.Cells[i].Controls[0];
31                            tb.Width=50;
32                        }

33                        catch(Exception ee)
34                        {
35                        }

36                    }

37                }

38            }

39        }
posted @ 2006-09-13 18:03  泡面 @ 幸福  阅读(227)  评论(0编辑  收藏  举报