【问题标题】:CSS style not apply to TextBox in GridView ItemTemplateCSS 样式不适用于 GridView ItemTemplate 中的 TextBox
【发布时间】:2013-06-25 10:46:31
【问题描述】:

我在GridView ItemTemplate 中有一个TextBox。我使用CssClass="txtboxAlignRight" 添加了css 样式。但是当我运行我的页面时,没有应用样式。

我在GridView FooterTemplate 中有另一个TextBox。我也将这种风格添加到TextBox。它工作正常。但是GridView 中的TextBox ItemTemplate 没有应用这种样式。

我该如何解决这个问题?

CSS

.txtboxAlignRight
{    
    text-align: right;
    border: 1px solid #ccc;
    border-radius: 4px;
    -moz-border-radius: 4px;
    -webkit-border-radius: 4px;         

}

aspx 页面

<ItemTemplate>
    <asp:TextBox ID="txt_cc" Width="150" runat="server" Text='<%# Bind("COUNT") %>'
        CssClass="txtboxAlignRight"></asp:TextBox>
</ItemTemplate>

【问题讨论】:

  • 你能提供你正在使用的css类和声明它的页面的一点sn-p吗?这可能有助于查看问题所在:)
  • @CarlosB 声明或 css 类没有错误。因为它在FooterTemplate 中正常工作。
  • 我已经更新了我的问题。
  • 所以在页面渲染时不会应用任何样式。好的,您是否定义了任何可能以某种方式改变行的 gridview 事件?喜欢 onRowDataBound?
  • @CarlosB 没有。没有任何 gridview 事件。

标签: asp.net css gridview textbox itemtemplate


【解决方案1】:

我已将以下代码添加到我的css 文件中。

input[type="text"]
{   
    border: 1px solid #ccc;
    border-radius: 4px;
    -moz-border-radius: 4px;
    -webkit-border-radius: 4px; 
}

这会将样式应用于我页面中的所有文本框。然后我在我的ItemTemplate 中添加了Style="text-align: right"TextBox

<ItemTemplate>
    <asp:TextBox ID="txt_cc" Width="150" runat="server" Text='<%# Bind("COUNT") %>'
        Style="text-align: right"></asp:TextBox>
</ItemTemplate>

【讨论】:

    【解决方案2】:

    在模板字段中使用这一行。

    ItemStyle-Horizo​​ntalAlign="Right"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-30
      • 1970-01-01
      • 1970-01-01
      • 2017-01-24
      • 2018-11-02
      • 1970-01-01
      • 2022-12-15
      相关资源
      最近更新 更多