.net 中怎样利用数据控件,同行数据输出两种样式的列表

一,html代码

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

<!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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:DataList ID="DataList1" runat="server" RepeatDirection="Horizontal" RepeatColumns="2">
   <ItemTemplate>
   <table width="129" border="0" cellpadding="0" cellspacing="0" class="TB-TWORE">
   <tr bgcolor="#2d6b86">
   <td height="29" align="center" valign="middle">
   <a href="#" class="linkWhite14"><%# Eval("Name") %></a>
   </td>
   </tr>
   <tr bgcolor="#2d6b86">
   <td height="29" align="center" valign="middle">
    <a href="#" class="linkWhite14"><%# Eval("Sex") %></a>
   </td>
   </tr>
   <tr bgcolor="#2d6b86">
   <td height="29" align="center" valign="middle">
    <a href="#" class="linkWhite14"><%# Eval("Age") %></a>
   </td>
   </tr>
   <tr bgcolor="#2d6b86">
   <td height="29" align="center" valign="middle">
    <a href="#" class="linkWhite14"><%# Eval("Money") %></a>
   </td>
   </tr>
  </table>
   </ItemTemplate>
   <AlternatingItemTemplate>
   <table width="129" border="0" cellpadding="0" cellspacing="0" class="TB-TWORE">
   <tr bgcolor="#08466d">
   <td height="29" align="center" valign="middle">
   <a href="#" class="linkWhite14"><%# Eval("Name") %></a>
   </td>
   </tr>
   <tr bgcolor="#08466d">
   <td height="29" align="center" valign="middle">
    <a href="#" class="linkWhite14"><%# Eval("Sex") %></a>
   </td>
   </tr>
   <tr bgcolor="#08466d">
   <td height="29" align="center" valign="middle">
    <a href="#" class="linkWhite14"><%# Eval("Age") %></a>
   </td>
   </tr>
   <tr bgcolor="#08466d">
   <td height="29" align="center" valign="middle">
    <a href="#" class="linkWhite14"><%# Eval("Money") %></a>
   </td>
   </tr>
  </table>
   </AlternatingItemTemplate>
   </asp:DataList>

    </div>
    </form>
</body>
</html>
二,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 Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }
    private void BindData()
    {
        List<People> list = new List<People>();
        list.Add(new People("李华", 35, "女", 266));
        list.Add(new People("李金", 20, "女", 1000000));
        list.Add(new People("李明", 10, "女", 2000));
        list.Add(new People("李月", 11, "女", 1000));
        list.Add(new People("李静", 23, "女", 100110000));
        list.Add(new People("李天", 11, "男", 2));
        list.Add(new People("李东", 11, "男", 10200000));
        list.Add(new People("李秋", 33, "男", 2));
        this.DataList1.DataSource = list;
        this.DataList1.DataBind();
    }
    public class People
    {

        private string name;
        private int age;
        private string sex;
        private int money;
        public People(string name, int age, string sex, int money)
        {
            this.name = name;
            this.sex = sex;
            this.age = age;
            this.money = money;
        }
        public string Name
        {
            get {
                return this.name;
            }
        }
        public int Age
        {
            get
            {
                return this.age;
            }
        }
        public string Sex
        {
            get
            {
                return this.sex;
            }
        }
        public int Money
        {
            get
            {
                return this.money;
            }
        }
    }

}

三,最张效果

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值