控制GridView中TextBox的宽度
1protected void GvAddWork_PreRender(object sender, EventArgs e)
2 {
3 if (GvAddWork.EditIndex > -1)
4 {
5 int intLength = 0;
6 for (int i = 1; i < GvAddWork.Rows[GvAddWork.EditIndex].Cells.Count - 3; i++)
7 {
8 TextBox TXTb = new TextBox();
9 TXTb = (TextBox)GvAddWork.Rows[GvAddWork.EditIndex].Cells[i].Controls[0];
10 intLength = TXTb.Text.Length;
11 intLength = intLength * 7;
12 if (intLength < 50)
13 intLength = 50;
14 TXTb.Width = intLength;
15 }
16 }
17 }
2 {
3 if (GvAddWork.EditIndex > -1)
4 {
5 int intLength = 0;
6 for (int i = 1; i < GvAddWork.Rows[GvAddWork.EditIndex].Cells.Count - 3; i++)
7 {
8 TextBox TXTb = new TextBox();
9 TXTb = (TextBox)GvAddWork.Rows[GvAddWork.EditIndex].Cells[i].Controls[0];
10 intLength = TXTb.Text.Length;
11 intLength = intLength * 7;
12 if (intLength < 50)
13 intLength = 50;
14 TXTb.Width = intLength;
15 }
16 }
17 }
1Private Sub DataGrid1_PreRender(s As Object, e As EventArgs)
2If DataGrid1.EditItemIndex > -1 Then
3 Dim tbx As TextBox
4 tbx = CType(DataGrid1.Items(DataGrid1.EditItemIndex).Cells(0).Controls(0), TextBox)
5 tbx.Width = Unit.Parse("1cm")
6End If
7End Sub
2If DataGrid1.EditItemIndex > -1 Then
3 Dim tbx As TextBox
4 tbx = CType(DataGrid1.Items(DataGrid1.EditItemIndex).Cells(0).Controls(0), TextBox)
5 tbx.Width = Unit.Parse("1cm")
6End If
7End Sub