【问题标题】:Text Align DropDownList List Item CENTER using datarowview使用datarowview文本对齐下拉列表列表项中心
【发布时间】:2011-03-08 05:20:47
【问题描述】:

我已经在 Table 和 paraent 控件中尝试了所有可以想象的 CSS,并且我正在使用 .NET 3.5 C# 中的 DataList 控件中的 DataRowView 填充和格式化 DropDownList。但我不能为我的生活,将下拉列表中的列表项居中。似乎最简单的方法是使用我现在在后面的页面中使用的相同格式化程序......这里是代码。

相信我 Div 标签在列表项上不起作用.. CSS 也不起作用。

如何设置 text-align: Center ??

    if (on == "True")
    {
        DropDownList dl1 = (DropDownList)e.Item.FindControl("ddlOn");
        dl1.BackColor = System.Drawing.Color.LightGreen;
        dl1.ForeColor = System.Drawing.Color.White;
        dl1.Font.Bold = true;
        ListItem li = dl1.Items.FindByValue("True");
        if (li != null)
        {
            li.Selected = true;
        }
    }

这里是DataList控件的ItemTemplate中的DropDownList。

                  <tr>
                    <td>
                        <asp:DropDownList ID="ddlOn" runat="server"
                                AutoPostBack="True" Width="100%" CssClass="cen3">
                            <asp:ListItem>True</asp:ListItem>
                            <asp:ListItem>False</asp:ListItem>
                        </asp:DropDownList>
                    </td>
                  </tr>

【问题讨论】:

  • 您希望文本对齐还是整个控件居中?

标签: .net drop-down-menu web-controls


【解决方案1】:

我假设您正在尝试将 DropDownList 控件居中到列的中心?

如果是这样,您需要从 DropDownList 中删除 Width="100%" 并将列 text-align 设置为 centered

<td style="text-align: center">
    <asp:DropDownList ID="ddlOn" runat="server" AutoPostBack="True" CssClass="cen3">
        <asp:ListItem>True</asp:ListItem>
        <asp:ListItem>False</asp:ListItem>
    </asp:DropDownList>
</td>

编辑:根据我已经能够测试,IE(至少到版本 8)不支持在选择或选项标签上设置文本对齐方式。通过直接在生成的 HTML 的 select 元素中设置它,我已经能够让它在 Chrome 和 Firefox 上运行。相同的 HTML 在 IE 中没有任何作用。

我认为您可能无法在 IE 中调整对齐方式。

编辑:在 SO 上找到这个问题,得出相同的结论:

.net dropdownlist align text

【讨论】:

  • 我试图将 ListItems 居中,它们位于左侧。我有 text-align:center as CssClass cen3 我发现它在 Firefox 中可以正常工作,但不是 IE,上面的 td 样式标签也没有..还有其他想法吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-10-20
  • 2015-05-12
  • 2015-11-22
  • 2014-03-22
  • 1970-01-01
  • 1970-01-01
  • 2015-12-09
相关资源
最近更新 更多