日期:2014-05-17  浏览次数:20689 次

GridView编辑时的TextBox宽度在样式中怎么改?
如题。
有超过10个GridView控件,编辑时TextBox很大求怎么在样式中修改。
我用的是一个skin文件
<asp:GridView  runat="server" AutoGenerateColumns="False" Width="998px"  CellPadding="4" ForeColor="#333333" GridLines="None" AutoSizeMode="None" style="word-break:break-all;word-wrap:break-word;table-layout:fixed;" ControlStyle-Width="10px">
    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />       
    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
    <EditRowStyle BackColor="#999999" />
    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>

如果可以在css中修改也可以

------解决方案--------------------
 Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowState = (DataControlRowState.Edit Or DataControlRowState.Alternate) OrElse e.Row.RowState = DataControlRowState.Edit Then
            Dim colText As TextBox
            For i As Integer = 0 To e.Row.Cells.Count - 1
                If e.Row.Cells(i).Controls.Count <> 0 Then
                    colText = TryCast(e.Row.Cells(i).Controls(0), TextBox)
                    If colText IsNot Nothing Then
                        colText.Width = Unit.Pixel(80)  '寬度設定
                    End If
                End If
            Next
        End If

    End Sub