c#
  • asp.net
  • gridview
  • styles
  • html
  • 2012-03-08 81 views 0 likes 
    0

    無法將數據綁定屬性Style無法將數據綁定`Style`屬性中的GridView

    Style='<%# Eval("LeftPadding","padding-left:{0}") %>' 
    

    全碼

    <asp:TemplateField HeaderText="Report Item" SortExpression="ReportItem"> 
        <ItemTemplate> 
         <asp:Label Style='<%# Eval("LeftPadding","padding-left:{0}") %>' ID="lblReportItem" 
          runat="server" Text='<%# Eval("Caption") %>'></asp:Label> 
        </ItemTemplate> 
        <ItemStyle Width="350px" /> 
    </asp:TemplateField> 
    

    但我甚至可以數據綁定一些其他屬性不是標準HTML屬性,如下所示

    <asp:Label StyleTemp='<%# Eval("LeftPadding","padding-left:{0}") %>' ID="lblReportItem" 
           runat="server" Text='<%# Eval("Caption") %>'></asp:Label> 
    

    Style有什麼問題?

    回答

    0

    得到了答案:)

    <asp:Label Style=<%# string.Format("padding-left:{0}px",Eval("LeftPadding")!=DBNull.Value? Convert.ToString(Eval("LeftPadding")): "0") %> 
                      ID="lblReportItem" runat="server" Text='<%# Eval("Caption") %>'></asp:Label> 
    

    試圖通過不給單引號爲style屬性和使用string.Format

    Style=<%# string.Format("padding-left:{0}px",Eval("LeftPadding")!=DBNull.Value? Convert.ToString(Eval("LeftPadding")): "0") %> 
    
    相關問題