【问题标题】:why does text move under checkbox instead of 1 line next to checkbox?为什么文本在复选框下移动,而不是复选框旁边的 1 行?
【发布时间】:2013-11-04 19:23:09
【问题描述】:

在 VB 代码中,在我创建 Div 以在 if 语句期间将文本更改为红色之前,文本与复选框对齐。现在,当我添加颜色更改代码child.Text = "<div style='color:Red; display: inline; float: left;'>" + child.Text & "</div>" 时,它会将文本移动到复选框下方而不是复选框旁边。我尝试了跨度,但它不起作用。我希望文本位于复选框旁边。

这里是详细的VB代码,

 'populate the child nodes
                While dr.Read()
                    Dim child As TreeNode = New TreeNode(dr("Name"), dr("Name"))
                    Dim complianceFlag As Boolean

                    If Boolean.TryParse(dr("Compliance"), complianceFlag) Then
                        ' Yes, compliance value is a Boolean, now set color based on value
                        If Not complianceFlag Then
                            child.Text = "<div style='color:Red; display: inline; float: left;'>" + child.Text & "</div>"
                        End If
                    Else

                    End If
                    rootNode.ChildNodes.Add(child)
                    child.SelectAction = TreeNodeSelectAction.None
                End While

HTML 代码,

<div>
  <asp:UpdatePanel ID="UpdatePanel6" runat="server">
   <ContentTemplate>
  <asp:TreeView onclick="client_OnTreeNodeChecked();" ID="TreeViewGroups" runat="server"
          ShowCheckBoxes="All" ExpandDepth="0" CssClass="bold">
         </asp:TreeView>
    <asp:Label ID="LabelNoServers" runat="server" Text=""></asp:Label>
   </ContentTemplate>
     <Triggers>
    <%--<asp:AsyncPostBackTrigger ControlID="b_DelYes" EventName="Click" />--%>
    </Triggers>
     </asp:UpdatePanel>
</div>

【问题讨论】:

  • 请发布页面中生成的 HTML 输出。听起来你有一个你不理解的浮动问题。
  • 我通过添加 HTML 代码编辑它

标签: asp.net css vb.net


【解决方案1】:

我找到了一个解决方案,我没有使用&lt;div&gt;,而是使用&lt;font&gt;。这样,它将切出空间并移回下一行复选框。

child.Text = "<font color='red'>" + child.Text + "</font>"

【讨论】:

  • 我不明白为什么我被否决了。这是唯一可行的简单解决方案。 Div、Span、p 等标签不起作用。
  • 这很可能被否决了,因为问题的措辞令人困惑,您也没有显示生成的 HTML,您只显示了 .aspx 页面 - 这不是呈现的 html。
猜你喜欢
  • 2018-05-22
  • 2013-08-22
  • 1970-01-01
  • 2015-03-20
  • 1970-01-01
  • 2020-11-27
  • 1970-01-01
  • 1970-01-01
  • 2023-01-11
相关资源
最近更新 更多