0

我的页面顶部有一个列表,上面有几个不同的国家。我需要有一个#anchor,它会在页面的中途弹出到所选国家/地区。但是,页面下方的国家/地区是从数据库中提取的,并由转发器中的超链接列出。

<td align="center">
  <ul style="list-style-type: none;">
     <li><a href="#USA">USA </a></li>
     <li><a href="#Canada">Canada </a></li>
     <li><a href="#Australia">Australia </a></li>
  </ul>
</td>

<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
  <ItemTemplate>
     <asp:HyperLink ID="hlCountryName" runat="server" Style="color: #6D94B8; font-size: 20px; font-weight: bold; margin-bottom: 5px; padding-left: 10px;"></asp:HyperLink>

在 C# 部分的 DataList1_ItemDataBound 方法中,我做了:

hlCountryName.Attributes.Add("href", "#" + drCountry[Common.Data.Country.Constants.countryName].ToString());

然而,当我点击页面顶部的链接时,我并没有被带到任何地方。我想知道我的代码中可能缺少什么?或者如果我错过了完全理解如何做到这一点?任何帮助表示赞赏。谢谢!

4

1 回答 1

0

您应该尝试替换此行:

hlCountryName.Attributes.Add("href", "#" + drCountry[Common.Data.Country.Constants.countryName].ToString());

和 :

hlCountryName.Attributes.Add("name",drCountry[Common.Data.Country.Constants.countryName].ToString());
于 2013-05-20T12:16:23.957 回答