WebForm控件Repeater
我们会发现用拼接字符串来显示一个查询非常的麻烦,有一个控件Repeater帮助你,省去写Foreach
LinQ to SQL类
函数类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; /// <summary>
/// fruitDA 的摘要说明
/// </summary>
public class fruitDA
{
private DataClasses2DataContext context;
public fruitDA()
{
context = new DataClasses2DataContext();
}
public List<fruit> select()
{
return context.fruit.ToList();
}
public string FriutName(int a)
{
var query = context.fruit.Where(p=>p.ids==a);
if (query.Count() > )
{
return query.First().name;
}
return null; }
public decimal FruitPrice(int a)
{
var query = context.fruit.Where(p=>p.ids==a);
if (query.Count() > )
{
return Convert.ToDecimal( query.First().price); }
return ;
} }
新建一页面,BODY中DIV加入Literal标签 后台写函数
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <!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>
</head>
<body>
<form id="form1" runat="server">
<div align="center">
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table><tr><td style="color:greenyellow">果果</td>
<td style="color:greenyellow">价格</td>
<td style="color:greenyellow">哪里滴</td>
<td style="color:greenyellow">库存</td></tr>
</HeaderTemplate>
<ItemTemplate>
<tr bgcolor="Yellow"><td><%#Eval("name") %></td>
<td><%#Eval("price") %></td>
<td><%#Eval("source") %></td>
<td><%#Eval("numbers") %></td>
<td><a href='Default3.aspx?ids=<%#Eval("ids") %>'>购买</a></td></tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr bgcolor="#f3e"><td><%#Eval("name") %></td>
<td><%#Eval("price") %></td><td><%#Eval("source") %></td>
<td><%#Eval("numbers") %></td>
<td><a href='Default3.aspx?ids=<%#Eval("ids") %>'>购买</a> </td></tr>
</AlternatingItemTemplate>
<FooterTemplate> </table></FooterTemplate> </asp:Repeater> </div>
</form>
</body>
</html>
Repeater里面有5个标签,4个常用
<HeaderTemplate>:添加表头.
<ItemTemplate>:类似于Body要查的数据引用C#代码 <%#Eval("列名")%> 用来传值.
<AlternatingItemTemplate>: 与<ItemTemplate>替换,先显示<ItemTemplate>.
<FooterTemplate>:表的脚.
后台绑定代码:
using System;
using System.Collections;
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)
{
Literal1.Text =f;
Repeater1.DataSource = new fruitDA().select();
Repeater1.DataBind();
}
} 这里绑定一个List<>泛型集合,最后要执行绑定 Repeater1.DataBind();
WebForm控件Repeater的更多相关文章
- 将开始我的WebForm控件开发之旅
时间总是过得很快,一转眼三个月就过去了,三个月内发生了很多的事.因为学校的学习,离开了我入门WPF的公司:开发了第一个外包项目,做的是WebForm的:而且了马上要毕业了,毕业后的公司应该是专门用We ...
- WebForm控件多字段绑定
一.这里的多字段绑定是什么意思? 多字段绑定控件其实就是把两个字段显示在一起作为一个字段现在控件上! 可能读者看了可能还是有点懵逼,说的还是比较抽象!的确,光从这上面的确是无法具体到某特定一种情况!那 ...
- 从数据库中,绑定JQuery Accordion控件---Repeater control
http://aspsnippets.com/Articles/jQuery-Accordion-example-in-ASPNet-using-C-and-VBNet.aspx 1. 添加JQuer ...
- WebForm 控件(二)
控件 Calendar:日历控件 但是html代码量太大不适用 FileUpdate: 文件上传 HiddenField:隐藏域 Image: 图片 可以直接给URL 不适用可用html代码写 Ta ...
- WebForm 控件(一)、连接数据库
一.控件 [简单控件] (一)文字显示 1.Label → 在html中相当于span <asp:Label ID="控件名 runat="server" Tex ...
- {Repeater控件} Repeater控件的用法流程及实例
一.Repeater控件的用法流程及实例: 1.首先建立一个网站,新建一个网页index.aspx. 2.添加或者建立APP_Data数据文件,然后将用到的数据库文件放到APP_Data文件夹中. 3 ...
- webform控件
简单控件: 1.Label 会被编译成span标签 属性: Text:文本内容 CssClass:CSS样式 <asp:Label ID=" CssClass="aaa&qu ...
- WebForm控件--2016年12月29日
简单控件 1.Label => <span id="Label1">Label1</span> 2.Literal => Text 填 ...
- 常用的WebForm 控件
首先回忆一下Html页中的12个表单元素 .文本类 文本框 <input type="text" id="" name="" valu ...
随机推荐
- Mac下Intellij IDEA Console中文是?
Mac下Intellij IDEA Console中文是?,解决办法是在运行时的VM参数配置也加入: -Dfile.encoding=UTF-8
- C#之数组篇
大杂烩 一.数组初始化 1.一维数组 String[] str = new String[3] { "1","2","3"}; ...
- 理解DOM
http://www.cnblogs.com/chaogex/p/3959723.html 文档对象模型(Document Object Model,简称DOM),是W3C组织推荐的处理可扩展标志语言 ...
- ElasticSearch-5.0安装head插件
环境 Windows10企业版X64 JDK-1.8 ElasticSearch-5.0.0 node-v4.5.0-x64.msi git客户端 步骤 安装node到D盘.如D:\nodejs. 把 ...
- js自执行函数注意事项
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 深入理解javascript原型和闭包(9)——简述【执行上下文】下
继续上一篇文章(http://www.cnblogs.com/wangfupeng1988/p/3986420.html)的内容. 上一篇我们讲到在全局环境下的代码段中,执行上下文环境中有如何数据: ...
- Effective Java Second Edition --- Builder Pattern
如果类的构造器或者静态工厂中有多个参数,设计这种类时,Builder模式是一种不错的选择,特别是当大多数参数是可选的时候. 与使用传统的重载构造函数模式相比,使用Builder模式的客户端代码更易于阅 ...
- Linux/CentOS下开启MySQL远程连接,远程管理数据库
当服务器没有运行PHP.没装phpMyAdmin的时候,远程管理MySQL就显得有必要了. 第一步:开启MySQL用户的远程访问权限 mysql -u root -p mysql # 第1个mysql ...
- 【转】8G内存下MySQL的优化详细方案
对于任何一个数据库管理系统来说,内存的分配使用绝对可以算的上是其核心之一了,所以很多希望更为深入了解某数据库管理系统的人,都会希望一窥究竟,我也不例外. 这里给出方案 按照下面的设置试试看: key_ ...
- Swift3.0P1 语法指南——控制流
原档:https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programmi ...