我正在尝试将交替行颜色应用于列表视图。
我将 css 包含在 aspx 页面的标题中,以防在引用的样式表中可能有其他东西覆盖它。
我在其他以声明方式在 aspx 页面上编写的列表视图中使用了完全相同的方法,它们按预期呈现。但是,这个listview是绑定在cs页面中的。它运行完美,只是它忽略了应用于类的任何 CSS 样式。
它生成的 HTML 源代码显示类正在正确地写入标签。作为第二种选择,我选择了 AlternatingTemplate 路线,再次将类成功写入 HTML 代码,但仍然没有 css 渲染。
是否有关于在 cs 页面中绑定列表视图以覆盖 aspx 页面中的样式的内容?谢谢。
ASPX:
<style>
.EvenRowColor{background-color:#FFF;}
.OddRowColor{background-color: #E9F1F3;}
</style>
<asp:ListView ID="lvOtherAccts" runat="server" ItemPlaceholderID=
"itemPlaceHolder">
<LayoutTemplate>
<table id="ConsumptionData">
<tr>
<th id="Th1" runat="server">
Account
</th>
<th id="Th2" runat="server">
Service Address
</th>
<th id="Th3" runat="server">
City
</th>
<th id="Th4" runat="server">
Last Bill Date
</th>
<th id="Th5" runat="server">
Billed Balance Due
</th>
</tr>
<tr ID="itemPlaceholder" runat="server"></tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr class='<%# Convert.ToBoolean(Container.DataItemIndex % 2) ? "OddRowColor" : "EvenRowColor" %>'>
<td>
<asp:Label ID="AcctNbr" runat="server" Text='<%#Eval("acct_nbr")%>' />
</td>
<td>
<asp:Label ID="SvcAddr" align="left" runat="server" Text='<%#Eval("svc_addr")%>' />
</td>
<td>
<asp:Label ID="SvcCity" runat="server" align="left" Text='<%#Eval("svc_city")%>' />
</td>
<td>
<asp:Label ID="BillDate" runat="server" Text='<%#DateTime.Parse(Eval("billing_date").ToString()).ToString("MM/dd/yyyy")%>' />
</td>
<td style="text-align: right; padding-right: 50px;">
<asp:Label ID="Balance" runat="server" Text='<%# Eval("w_bal", "{0:C2}") %>' />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
CS:
String strConnString10 = WebConfigurationManager.ConnectionStrings["billing_webConnectionString"].ConnectionString;
SqlConnection con10 = new SqlConnection(strConnString10);
SqlCommand cmd10 = new SqlCommand("SELECT landlord_nbr, svc_addr, svc_addr2, svc_city, svc_state, svc_zip, acct_nbr, billing_date, w_bal from landlord_info where landlord_nbr='" + ll_num + "'ORDER BY acct_nbr ASC", con10);
cmd10.Parameters.Add("conn_nbr", SqlDbType.VarChar).Value = Session["LLNum"];
cmd10.Connection = con10;
SqlDataAdapter da10 = new SqlDataAdapter(cmd10);
DataTable dtLLAccts = new DataTable();
da10.Fill(dtLLAccts);
lvOtherAccts.DataSource = dtLLAccts;
lvOtherAccts.DataBind();
HTML 输出片段:
<tr class='EvenRowColor'>
<td>
<span id="ContentPlaceHolderMain_lvOtherAccts_AcctNbr_0">209495000</span>
</td>
<td>
<span id="ContentPlaceHolderMain_lvOtherAccts_SvcAddr_0" align="left">266 SEAVER ST </span>
</td>
<td>
<span id="ContentPlaceHolderMain_lvOtherAccts_SvcCity_0" align="left">ROXBURY </span>
</td>
<td>
<span id="ContentPlaceHolderMain_lvOtherAccts_BillDate_0">07/21/2014</span>
</td>
<td style="text-align: right; padding-right: 50px;">
<span id="ContentPlaceHolderMain_lvOtherAccts_Balance_0">$1,925.68</span>
</td>
</tr>
<tr class='OddRowColor'>
<td>
<span id="ContentPlaceHolderMain_lvOtherAccts_AcctNbr_1">209642001</span>
</td>
<td>
<span id="ContentPlaceHolderMain_lvOtherAccts_SvcAddr_1" align="left">47 NAZING ST </span>
</td>
<td>
<span id="ContentPlaceHolderMain_lvOtherAccts_SvcCity_1" align="left">ROXBURY </span>
</td>
<td>
<span id="ContentPlaceHolderMain_lvOtherAccts_BillDate_1">07/21/2014</span>
</td>
<td style="text-align: right; padding-right: 50px;">
<span id="ContentPlaceHolderMain_lvOtherAccts_Balance_1">$571.06</span>
</td>
</tr>