如何控制DataGrid在编辑状态下文本框的宽度
1 private void dgShow_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
2 {
3 if (e.Item.ItemType == ListItemType.EditItem)
4 {
5 for (int i=0;i<e.Item.Cells.Count;i++)
6 {
7 if(e.Item.Cells[i].Controls.Count>0)
8 {
9 try
10 {
11 TextBox t =(TextBox)e.Item.Cells[i].Controls[0];
12 t.Width=130;
13 }
14 catch(Exception ee)
15 {
16 }
17 }
18 }
19 }
20 }
当然在此里面还可以作更丰富的一些操作,如在某列添加一编辑状态下的文本框和下拉列表框,这样我们可以为列表控件在编辑状态下绑定需要使用的数据.等等.......其中奥妙有待各位去发掘.
2 {
3 if (e.Item.ItemType == ListItemType.EditItem)
4 {
5 for (int i=0;i<e.Item.Cells.Count;i++)
6 {
7 if(e.Item.Cells[i].Controls.Count>0)
8 {
9 try
10 {
11 TextBox t =(TextBox)e.Item.Cells[i].Controls[0];
12 t.Width=130;
13 }
14 catch(Exception ee)
15 {
16 }
17 }
18 }
19 }
20 }
浙公网安备 33010602011771号