asp.net--ListView小例子

.aspx代码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ListView练习.aspx.cs" Inherits="ListView练习" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
   <span style="color:#cc0000;"> body,div,p,img,h1,h2,h3,h4,h5{ margin:0px; padding:0px;}</span>
      .fl{ float:left;}
      .fr{ float:right;}
      .clr{ clear:both;}
      h1{ padding:15px;border-bottom:1px solid gray;}
      #div_listview{ width: 700px; }
      #div_menu{ width:300px;}
      .divItem{ border-bottom:1px dashed #ededed; margin-bottom:10px; padding:10px;}
        .divItem img{ margin-right:10px; float:left;padding:3px; background-color:White; border:1px solid #eaeaea;} 
        .divItem h2{ font-family:微软雅黑; font-size:16px; color:#444; letter-spacing:1px;
                      margin:0px 10px 0px 10px;}
         .divItem p{ font-size:12px;color:#888; margin-bottom:10px;  margin:10px 10px 10px 10px;}    
         .divItem a{ text-decoration:none;float:right; color:Black; margin-bottom:10px;} 
         .divItem a:hover{ color:Blue; }  
         .divItem:hover{ background-color:Gray;}      
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h1>新闻列表</h1>
    <div id="div_listview" class="fl">
        <asp:ListView ID="ListView1" runat="server" ItemPlaceholderID="itemHolder" DataSourceID="AccessDataSource2">
        <LayoutTemplate>
        <div runat="server" id="itemHolder">
        </div>
        </LayoutTemplate>
        <ItemTemplate>
        <div class="divItem" id="a1" runat="server">
        <img  alt="" src='<%#Eval("news_picsrc","imgs/{0}") %>' />
        
        <div class="fl">
        <h2><%#Eval("news_ttl") %></h2>
        <p><%#Eval("news_date","{0:D}") %></p>
        <span style="color:#cc0000;"><a href="news_detail.aspx?nid=<%#Eval("news_id") %>">详细内容</a></span>
        </div>
        <div class ="clr"></div>
       
        </div>
        
        </ItemTemplate>
        </asp:ListView>
        <asp:AccessDataSource ID="AccessDataSource2" runat="server" 
            DataFile="~/mdb/mydb.mdb" 
            SelectCommand="SELECT * FROM [tb_news] WHERE ([news_cid] = ?)">
            <SelectParameters>
                <asp:SessionParameter DefaultValue="0" Name="news_cid" SessionField="CID" 
                    Type="Int32" />
            </SelectParameters>
        </asp:AccessDataSource>
    </div>
    <div id="div_menu" class="fr">
    
        <asp:BulletedList ID="BulletedList1" runat="server"  DisplayMode="LinkButton"
            DataSourceID="AccessDataSource1" DataTextField="lnc_name" 
            DataValueField="lnc_id" οnclick="BulletedList1_Click">
        </asp:BulletedList>
        <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
            DataFile="~/mdb/mydb.mdb" 
            SelectCommand="SELECT [lnc_id], [lnc_name] FROM [list_newsclass]">
        </asp:AccessDataSource>
    </div>
    <div class="clr"></div>
    </div>
    </form>
</body>
</html>
.aspx.cs代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ListView练习 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void BulletedList1_Click(object sender, BulletedListEventArgs e)
    {
        Session["CID"] = BulletedList1.Items[e.Index].Value;
    }
}


效果如下:


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值