ASP.net DataList控件

2022/1/13 1:12:32

本文主要是介绍ASP.net DataList控件,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

一.说明

此控件的用法与**Repeater,**类似,如有需要请移步ASP.net Repeater控件

二.步骤

添加控件
在这里插入图片描述
并点击属性生成器…

选择直接需要的属性:
在这里插入图片描述

三.前端代码

前端代码只是简单的布置

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="WebApplication6.WebForm3" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <style>
        td{
            border:1px solid #000000;
            border-collapse:collapse;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:DataList ID="DataList1" runat="server" RepeatColumns="2" RepeatDirection="Horizontal">
            <%--同样也是有页眉,页未等等--%>
                <ItemTemplate>
                    <table>
                        <tr>
                            <td><%#Eval("id") %></td>
                            <td><%#Eval("name") %></td>
                        </tr>
                    </table>
                </ItemTemplate>
            </asp:DataList>
        </div>
    </form>
</body>
</html>

四.后端代码

后端代码并没有怎么改变:

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

namespace WebApplication6
{
    public partial class WebForm3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DataList1.DataSource = MyDBSql.excutSql("select * from student");
            DataList1.DataBind();
        }
    }
}

界面效果:
在这里插入图片描述



这篇关于ASP.net DataList控件的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程