我正在尝试复制this页面上的“服务标签”部分,here是源代码。
我希望它看起来像这样:
我设法让它显示:
以下是我的ASPX:
<asp:Repeater ID="rptGroupDescriptions" runat="server" OnItemDataBound="rptGroupDescriptions_ItemDataBound" OnItemCommand="rptGroupDescriptions_ItemCommand">
<ItemTemplate>
<ul id="myTab" class="nav nav-tabs nav-justified">
<li>
<a href="#service-<%#Eval("Group_Id") %>" data-toggle="tab"><%#Eval("Group_Name")%></a>
</li>
</ul>
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade active in" id="service-<%#Eval("Group_Id") %>">
<h4><%#Eval("Group_Name")%></h4>
<p><%#Eval("Group_Desc")%></p>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
以下是我使用的示例代码:
<ul id="myTab" class="nav nav-tabs nav-justified">
<li class="active"><a href="#service-one" data-toggle="tab"><i class="fa fa-tree"></i> Service One</a>
</li>
<li class=""><a href="#service-two" data-toggle="tab"><i class="fa fa-car"></i> Service Two</a>
</li>
<li class=""><a href="#service-three" data-toggle="tab"><i class="fa fa-support"></i> Service Three</a>
</li>
<li class=""><a href="#service-four" data-toggle="tab"><i class="fa fa-database"></i> Service Four</a>
</li>
</ul>
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade active in" id="service-one">
<h4>Service One</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae repudiandae fugiat illo cupiditate excepturi esse officiis consectetur, laudantium qui voluptatem. Ad necessitatibus velit, accusantium expedita debitis impedit rerum totam id. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Natus quibusdam recusandae illum, nesciunt, architecto, saepe facere, voluptas eum incidunt dolores magni itaque autem neque velit in. At quia quaerat asperiores.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae repudiandae fugiat illo cupiditate excepturi esse officiis consectetur, laudantium qui voluptatem. Ad necessitatibus velit, accusantium expedita debitis impedit rerum totam id. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Natus quibusdam recusandae illum, nesciunt, architecto, saepe facere, voluptas eum incidunt dolores magni itaque autem neque velit in. At quia quaerat asperiores.</p>
</div>
<div class="tab-pane fade" id="service-two">
<h4>Service Two</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae repudiandae fugiat illo cupiditate excepturi esse officiis consectetur, laudantium qui voluptatem. Ad necessitatibus velit, accusantium expedita debitis impedit rerum totam id. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Natus quibusdam recusandae illum, nesciunt, architecto, saepe facere, voluptas eum incidunt dolores magni itaque autem neque velit in. At quia quaerat asperiores.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae repudiandae fugiat illo cupiditate excepturi esse officiis consectetur, laudantium qui voluptatem. Ad necessitatibus velit, accusantium expedita debitis impedit rerum totam id. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Natus quibusdam recusandae illum, nesciunt, architecto, saepe facere, voluptas eum incidunt dolores magni itaque autem neque velit in. At quia quaerat asperiores.</p>
</div>
<div class="tab-pane fade" id="service-three">
<h4>Service Three</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae repudiandae fugiat illo cupiditate excepturi esse officiis consectetur, laudantium qui voluptatem. Ad necessitatibus velit, accusantium expedita debitis impedit rerum totam id. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Natus quibusdam recusandae illum, nesciunt, architecto, saepe facere, voluptas eum incidunt dolores magni itaque autem neque velit in. At quia quaerat asperiores.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae repudiandae fugiat illo cupiditate excepturi esse officiis consectetur, laudantium qui voluptatem. Ad necessitatibus velit, accusantium expedita debitis impedit rerum totam id. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Natus quibusdam recusandae illum, nesciunt, architecto, saepe facere, voluptas eum incidunt dolores magni itaque autem neque velit in. At quia quaerat asperiores.</p>
</div>
<div class="tab-pane fade" id="service-four">
<h4>Service Four</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae repudiandae fugiat illo cupiditate excepturi esse officiis consectetur, laudantium qui voluptatem. Ad necessitatibus velit, accusantium expedita debitis impedit rerum totam id. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Natus quibusdam recusandae illum, nesciunt, architecto, saepe facere, voluptas eum incidunt dolores magni itaque autem neque velit in. At quia quaerat asperiores.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae repudiandae fugiat illo cupiditate excepturi esse officiis consectetur, laudantium qui voluptatem. Ad necessitatibus velit, accusantium expedita debitis impedit rerum totam id. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Natus quibusdam recusandae illum, nesciunt, architecto, saepe facere, voluptas eum incidunt dolores magni itaque autem neque velit in. At quia quaerat asperiores.</p>
</div>
</div>
我假设一个问题可能是我没有在列表项中添加class =“Active”,但我不能,因为那时每个列表项都会有该类。
所以这是我的Code Behind代码:
//Trying to display group descriptions using repeater
SqlConnection connGroupDesc;
string connStringGroupDesc = ConfigurationManager.ConnectionStrings[
"BallinoraDBConnectionString1"].ConnectionString;
connGroupDesc = new SqlConnection(connStringGroupDesc);
SqlDataAdapter sdaGroupDesc = new SqlDataAdapter("SELECT * FROM Groups", connGroupDesc);
DataTable dtGroupDesc = new DataTable();
sdaGroupDesc.Fill(dtGroupDesc);
rptGroupDescriptions.DataSource = dtGroupDesc;
rptGroupDescriptions.DataBind();
有人可以建议我如何改进我的上述代码来解决这个问题吗?
答案 0 :(得分:1)
您可以在使用ItemTemplate
的{{1}}中使用三元运算符
ItemIndex
这样,只有第一个<ul id="myTab" class="nav nav-tabs nav-justified" <%# Container.ItemIndex == 0 ? "class=\"Active\"" : string.Empty %>>
会有<ul>
类。