服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

服务器之家 - 编程语言 - ASP.NET教程 - ASP.NET列出数据库活跃链接的方法

ASP.NET列出数据库活跃链接的方法

2019-12-18 15:58小卒过河 ASP.NET教程

这篇文章主要介绍了ASP.NET列出数据库活跃链接的方法,实例分析了asp.net列出数据库活跃链接的原理与实现技巧,需要的朋友可以参考下

本文实例讲述了ASP.NET列出数据库活跃链接的方法。分享给大家供大家参考。具体分析如下:

这里列出数据库的活跃链接。主要使用geeric列表和一个贮存器,创建一个泛型列表的链接,如果他们是活跃的,那么他们将显示在导航了。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//First in C# where you create the controller action method
//to create the method that will populate all content details
//add the following code
public ActionResult Details(int id)
{
 var repositoryList = _repository.List();
 ViewData["List"] = repositoryList;
 return View(_repository.Get(id));
}
<!--now is ASP.net add the following in your navigation panel->
<ul>
  <% foreach (var item in (List<Service>)ViewData["List"])
  {%>
   <% if ((item.isActive) || (item.id != 0))
    { %><li><%=Html.ActionLink(item.Title, "Details", new { id = item.id })%></li><%} %>
  <%} %>
</ul>

希望本文所述对大家的asp.net程序设计有所帮助。

延伸 · 阅读

精彩推荐