2012-10-09 26 views
0

我有這個gridview,我想將一些樣式表設置應用於gridview中的驗證器。這裏是我的GV是如何設置:將樣式表應用到gridview模板域

<table class="table">            
<tr> 
    <td align="center" colspan="4"> 
     <cc1:GroupedGridView ID="grpgrdHeatPumpSPF" runat="server" BackColor="White" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" CellSpacing="2" 
      Width="650" GroupingDepth="3" AutoGenerateColumns="false" PageSize="20" AllowPaging="true" 
      DataKeyNames="HeatPumpID" OnPageIndexChanging="grpgrdHeatPumpSPF_PageIndexChanging" 
      OnRowCancelingEdit="grpgrdHeatPumpSPF_RowCancelingEdit" OnRowEditing="grpgrdHeatPumpSPF_RowEditing" OnRowUpdating="grpgrdHeatPumpSPF_RowUpdating" > 
     <HeaderStyle BackColor="#86C708" Font-Bold="True" ForeColor="White" HorizontalAlign="Left"></HeaderStyle> 
     <FooterStyle BackColor="White" ForeColor="#000066"></FooterStyle> 
     <RowStyle BackColor="White" ForeColor="#333333" HorizontalAlign="Left"></RowStyle> 
     <EditRowStyle BackColor="#cde686" /> 
     <SelectedRowStyle BackColor="#FCADAD" ForeColor="Black" Font-Bold="true" />        
     <AlternatingRowStyle ForeColor="#284775" /> 
     <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Left"></PagerStyle> 
     <PagerSettings Mode="NumericFirstLast" /> 
     <EmptyDataRowStyle CssClass="Label_Small_Bold" ForeColor="#C00000" HorizontalAlign="Center" />         
     <Columns> 
      <asp:ButtonField CommandName="Select" Visible="false" /> 
      <asp:BoundField DataField="HeatPumpID" HeaderText="HeatPumpID" Visible="False" ReadOnly="True" > 
       <HeaderStyle HorizontalAlign="Left" /> 
      </asp:BoundField> 
      <asp:BoundField DataField="ModelNumber" HeaderText="Model Number" Visible="True" ReadOnly="True" > 
       <HeaderStyle HorizontalAlign="Left" /> 
      </asp:BoundField> 
      <asp:TemplateField HeaderText="FlowTemp"> 
       <ItemTemplate> 
        <asp:Label ID="lblFlowTemp" runat="server" Text='<%# Bind("FlowTemp") %>'></asp:Label> 
       </ItemTemplate> 
       <ControlStyle CssClass="Input_Text_Int" /> 
       <HeaderStyle HorizontalAlign="Left" /> 
       <ItemStyle VerticalAlign="Top" /> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText="Heating"> 
       <EditItemTemplate> 
        <asp:TextBox ID="txtSPFHeating" runat="server" Text='<%# Bind("SPFHeating") %>' CssClass="Input_Text_Int"></asp:TextBox> 
        <asp:RequiredFieldValidator Display="Dynamic" CssClass="validateGridView" ID="validateBTSPFHeating" runat="server" 
         ErrorMessage="Please enter SPFHeating (e.g. 3.3)" ControlToValidate="txtSPFHeating"></asp:RequiredFieldValidator>       
        <asp:RegularExpressionValidator ID="regExpSPFHeating" runat="server" ControlToValidate="txtSPFHeating" CssClass="validateGridView" 
         ErrorMessage="Invalid SPFHeating (e.g. 3.3)" ValidationExpression="\d+(\.\d)" Display="Dynamic" SetFocusOnError="True"></asp:RegularExpressionValidator> 
       </EditItemTemplate> 
       <ItemTemplate> 
        <asp:Label ID="lblSPFHeating" runat="server" Text='<%# Bind("SPFHeating") %>'></asp:Label> 
       </ItemTemplate> 
       <ControlStyle CssClass="Input_Text_Int" /> 
       <HeaderStyle HorizontalAlign="Left" /> 
       <ItemStyle VerticalAlign="Top" /> 
      </asp:TemplateField> 
      <asp:CommandField ButtonType="Button" ShowEditButton="True" ValidationGroup="vgEdit"> 
         <ControlStyle CssClass="Button_XSmall" /> 
        </asp:CommandField> 
      <asp:TemplateField ShowHeader="False"> 
       <ItemTemplate> 
        <asp:Button ID="btnDeleteHeatPumpSPF" CommandArgument='<%# Eval("HeatPumpID","") + ";" + Eval("FlowTemp","") %>' runat="server" OnClientClick="return ConfirmDeletion();" CausesValidation="false" 
        CommandName="DeletePart" Text="Delete" OnClick="btnDeleteHeatPumpSPF_Click" /> 
       </ItemTemplate> 
       <ControlStyle CssClass="Label_Small" /> 
      </asp:TemplateField>          
     </Columns> 
    </cc1:GroupedGridView> 
    </td> 
</tr>      

和我的CSS如下:

table td 
{ 
padding: 2px; 
} 
table.center { 
    width:90%; 
    margin-left:5%; 
    margin-right:5%; 
    } 
.hideGridColumn 
{ 
    display:none; 
} 
.table td label{ 
    float: left; 
    width:146px; 
    margin-bottom:5px; 
    margin-top:5px; 
    font-family:Arial, Helvetica, sans-serif; 
    font-size:14px; 
    color: Black; 
    line-height: 17px; 
    text-align: right; 
} 
.table td labelmid{ 
    float: left; 
    width:205px; 
    margin-bottom:5px; 
    margin-top:5px; 
    text-align: right; 
} 
.table td labelwide{ 
    float: left; 
    width:230px; 
    margin-bottom:5px; 
    margin-top:5px; 
    text-align: right; 
} 
.table td.control{ 
    width:310px; 
    margin-bottom:5px; 
    vertical-align:middle; 
    font-family:Arial, Helvetica, sans-serif; 
    font-size:14px; 
    color: Black; 
    line-height: 17px; 
} 
.table td.controlmed{ 
    width:200px; 
    margin-bottom:5px; 
    vertical-align:middle; 
    font-family:Arial, Helvetica, sans-serif; 
    font-size:14px; 
    color: Black; 
    line-height: 17px; 
} 
.table td input[type=text],input[type=password]{ 
    float: left; 
    border:#92d307 solid 1px; 
    line-height:20px; 
    font-family:Arial, Helvetica, sans-serif; 
    padding:5px; 
    color:#000000; 
} 
.table td select{ 
    float: left; 
    border:#92d307 solid 1px; 
    height:32px; 
    line-height:20px; 
    font-family:Arial, Helvetica, sans-serif; 
    padding:5px; 
    color:#000000; 
    width:270px; 
} 
.Input_Text_Int{ 
    width:40px; 
    margin-bottom:10px; 
    vertical-align:middle; 
    padding-right:10px; 
} 
.Input_Text_Short 
{ 
    width:100px; 
    margin-bottom:10px; 
    vertical-align:middle; 
    padding-right:10px; 
} 
.Input_Text_Med 
{ 
    width:175px; 
    margin-bottom:10px; 
    vertical-align:middle; 
    padding-right:10px; 
} 
.Input_Text_Long 
{ 
    width:250px; 
    margin-bottom:10px; 
    vertical-align:middle; 
    padding-right:10px; 
} 
validateGridView 
{ 
    background: url(../images/wrongIconGV.png) left 5px no-repeat; 
    float: left; 
    font-family: Arial, Helvetica, sans-serif; 
    color: #FF5B5B; 
    font-size:8px; 
} 

模板字段應用Input_Text_Int設置,但不validateGridView設置。任何人都可以幫助我解決這個問題,所以驗證的格式與CSS中指定的一樣。

回答

1
CssClass="validateGridView" 

這是一類,所以我認爲你必須在你的CSS加點這樣

.validateGridView 
{ 
    background: url(../images/wrongIconGV.png) left 5px no-repeat; 
    float: left; 
    font-family: Arial, Helvetica, sans-serif; 
    color: #FF5B5B; 
    font-size:8px; 
} 
+0

我只是試着加入了點,但仍然沒有被應用的風格,驗證文本與正在編輯的行的風格類似 – paulmcm

+0

也許更具體的添加所有的類(見http://stackoverflow.com/questions/558721/css-classes-subclasses)與。表格.validateGridView – bAN

+0

我'已經找到了驗證器類被這個覆蓋的問題:刪除這一行已經解決了我的問題。無論如何,感謝您的幫助 – paulmcm