【问题标题】:Need to add a horizontal line to divide the rows in asp gridview需要添加一条水平线来划分asp gridview中的行
【发布时间】:2017-08-14 08:28:09
【问题描述】:

我有一个要求,我需要使用控件创建动态行,为此我使用了 gridview。问题是我无法在行之间显示黑色水平线。

要求:

我的设计:

css:

.alternateStyler {
margin-top:2px;  // just wanted to see if it works, did not work though.    
}

代码:

<asp:GridView ID="gvDelayIssueRisk" Width="98%" CssClass="labels" runat="server" ShowFooter="true" AutoGenerateColumns="false"
   Style="margin-left: auto; margin-right: auto;"
   OnSelectedIndexChanging="gvDelayIssueRisk_SelectedIndexChanging"
   OnRowDataBound="gvDelayIssueRisk_RowDataBound"
   AlternatingRowStyle-CssClass="alternateStyler">
   <Columns>
      <%--   <asp:BoundField DataField="noteid" HeaderText="ID" />--%>
      <asp:TemplateField HeaderText="Type" ItemStyle-Width="10%" ItemStyle-VerticalAlign="Top" FooterStyle-VerticalAlign ="Top">
         <ItemTemplate>
            <asp:Label ID="lblType" runat="server" Text='<%# Eval("Author") %>' Visible="false" />
            <asp:DropDownList ID="ddlType" Width="98%" runat="server" CssClass="DropDownListStyle"></asp:DropDownList>
         </ItemTemplate>
         <FooterTemplate>
            <asp:DropDownList ID="ddlType2" Width="98%" runat="server" CssClass="DropDownListStyle"></asp:DropDownList>
         </FooterTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderText="Impact" ItemStyle-Width="10%" ItemStyle-VerticalAlign="Top" FooterStyle-VerticalAlign ="Top">
         <ItemTemplate>
            <asp:Label ID="lblImpact" runat="server" Text='<%# Eval("Author") %>' Visible="false" />
            <asp:DropDownList ID="ddlImpact" Width="98%" runat="server" CssClass="DropDownListStyle"></asp:DropDownList>
         </ItemTemplate>
         <FooterTemplate>
            <asp:DropDownList ID="ddlImpact2" Width="98%" runat="server" CssClass="DropDownListStyle"></asp:DropDownList>
         </FooterTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderText="DIR Description" ItemStyle-Width="20%" ItemStyle-VerticalAlign="Top" FooterStyle-VerticalAlign ="Top">
         <ItemTemplate>
            <asp:TextBox ID="txtDIRDesc" Width="98%" TextMode="MultiLine" Height="100px" runat="server" Text='<%# Eval("notes")%>'></asp:TextBox>
         </ItemTemplate>
         <FooterTemplate>
            <asp:TextBox ID="txtDIRDesc2" Width="98%" TextMode="MultiLine" Height="100px" runat="server"></asp:TextBox>
         </FooterTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderText="Remediation Plan" ItemStyle-Width="20%" ItemStyle-VerticalAlign="Top" FooterStyle-VerticalAlign ="Top">
         <ItemTemplate>
            <asp:TextBox ID="txtRemPlan" Width="98%" TextMode="MultiLine" Height="100px" runat="server" Text='<%# Eval("notes")%>'></asp:TextBox>
         </ItemTemplate>
         <FooterTemplate>
            <asp:TextBox ID="txtRemPlan2" Width="98%" TextMode="MultiLine" Height="100px" runat="server"></asp:TextBox>
         </FooterTemplate>
      </asp:TemplateField>
                                            <asp:TemplateField HeaderText="Owner" ItemStyle-Width="10%" ItemStyle-VerticalAlign="Top" FooterStyle-VerticalAlign ="Top">
                                                <ItemTemplate>
                                                    <asp:TextBox ID="txtOwner" Width="98%" runat="server" Text='<%# Eval("notes")%>'></asp:TextBox>
                                                </ItemTemplate>
                                                <FooterTemplate>
                                                    <asp:TextBox ID="txtOwner2" Width="98%" runat="server"></asp:TextBox>
                                                </FooterTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="Due Date" ItemStyle-Width="8%" ItemStyle-VerticalAlign="Top" FooterStyle-VerticalAlign ="Top">
                                                <ItemTemplate>
                                                    <asp:TextBox ID="dtDueDate" CssClass="Datetext" Width="98%" runat="server" Text='<%# Eval("DateAdded")%>'></asp:TextBox>
                                                </ItemTemplate>
                                                <FooterTemplate>
                                                    <asp:TextBox ID="dtDueDate2" CssClass="Datetext" Width="98%" runat="server">
                                                    </asp:TextBox>
                                                </FooterTemplate>
                                            </asp:TemplateField>
                                             <asp:TemplateField HeaderText="Complete Date" ItemStyle-Width="8%" ItemStyle-VerticalAlign="Top" FooterStyle-VerticalAlign ="Top">
                                                <ItemTemplate>
                                                    <asp:TextBox ID="dtCompleteDate" CssClass="Datetext" Width="98%" runat="server" Text='<%# Eval("DateAdded")%>'></asp:TextBox>
                                                </ItemTemplate>
                                                <FooterTemplate>
                                                    <asp:TextBox ID="dtCompleteDate2" CssClass="Datetext" Width="98%" runat="server">
                                                    </asp:TextBox>
                                                </FooterTemplate>
                                            </asp:TemplateField> 
                                            <asp:TemplateField HeaderText="Notes" ItemStyle-Width="20%" ItemStyle-VerticalAlign="Top" FooterStyle-VerticalAlign ="Top">
                                                <ItemTemplate>
                                                    <asp:TextBox ID="txtDelayNotes" Width="98%" TextMode="MultiLine" Height="100px" runat="server" Text='<%# Eval("notes")%>'></asp:TextBox>
                                                </ItemTemplate>
                                                <FooterTemplate>
                                                    <asp:TextBox ID="txtDelayNotes2" Width="98%" TextMode="MultiLine" Height="100px" runat="server"></asp:TextBox>
                                                </FooterTemplate>
                                            </asp:TemplateField>
                                        </Columns>
                                    </asp:GridView>

【问题讨论】:

    标签: c# html css asp.net gridview


    【解决方案1】:

    你可以这样试试

    <asp:TemplateField HeaderText="Headername" ItemStyle-CssClass="Hrline" HeaderStyle-CssClass="Hrline"> </<asp:TemplateField>
    

    并在您的页面中添加以下 css

       <style type="text/css">
        .Hrline{ border-bottom:solid 1px black;}
        </style>
    

    【讨论】:

      【解决方案2】:

      将ItemStyle-CssClass 添加到网格中的每个TemplateField,即

      <asp:TemplateField HeaderText="Type" ItemStyle-CssClass="someClass"  ItemStyle-Width="10%" ItemStyle-VerticalAlign="Top" FooterStyle-VerticalAlign ="Top">...
      

      someClass 规则的定义应如下所示:

      <style type="text/css">
      .someClass
      {
        border-bottom:solid 1px black;
      }
      </style> 
      

      【讨论】:

      • 刚刚添加了 padding-bottom:1em;填充顶部:1em;和 FooterStyle-CssClass="SomeClass" ,解决了它。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      • 2021-12-15
      • 2016-03-25
      • 1970-01-01
      • 2019-08-15
      • 2017-09-11
      相关资源
      最近更新 更多