【发布时间】:2017-04-24 20:29:34
【问题描述】:
我目前正在尝试创建一个网站,当使用下拉列表选择某个品牌、型号、年份时动态显示项目。使用 HtmlAgilityPack 的网络爬虫检索项目信息。
所以我目前有一个数据库表,其中包含数千个项目,其中包含以下列:id、Make、Model、Year、PartCategory、PartUrl、ImageUrl、PartBrand、PartName、PartPrice。
我正在尝试做的是将每个站点分成 div,以便用户可以轻松判断他们正在查看的项目来自哪个站点。示例:
<div id="siteOne">
<table>
<tr>
<td>
<img url="ImageUrl">
<a href="PartUrl">PartBrand & PartName & PartPrice</a>
</td>
</tr>
<tr>
<td>
<img url="ImageUrl">
<a href="PartUrl">PartBrand & PartName & PartPrice</a>
</td>
</tr>
</table>
</div>
<div id="siteTwo">
.............
</div>
<div id=""siteThree>
.............
</div>
我目前总共只使用三个站点,我可以轻松地将数据拉入 DataTable 中,然后查看返回了多少行,所以这个数字就是我需要创建多少动态实例。我很确定 Jquery 可以处理这项工作,但是我找不到任何使用 DataTable 的 DataRows 来控制动态部分的人的例子,通常是使用按钮事件或类似的东西。
我想代码看起来像这样:
//this foreach statement will be in the last dropdown list's SelectedIndexChanged event
//when the last dropdown is chosen, a datatable will be returned with all the items that match that particular make/model/year
foreach (DataRow tempRow in tempDataTable)
{
//this should pull data from each column one at a time
//column: 0 = id, 1 = Make, 2 = Model, 3 = Year, don't think I'll need these right now
string partCategory = tempRow[4].ToString();
string partUrl = tempRow[5].ToString();
string imageUrl = tempRow[6].ToString();
string partBrand = tempRow[7].ToString();
string partName = tempRow[8].ToString();
string partPrice = tempRow[9].ToString();
//this is where the jquery would generate the dynamic elements in the table.
//three main divs can be hard coded for now, only using 3 sites currently
//this means the <table></table> in each will most likely be hard coded as well
//the <tr></tr>, <td></td>, <img>, and <a></a> will need to be generated dynamically each loop iteration
}
我已经在这一步上工作了一段时间,所以我想我会发帖看看是否有人有任何提示或类似的例子,同时我继续尝试自己解决它。任何事情都会非常感激。干杯!
【问题讨论】:
标签: javascript c# jquery html css