我们会发现用拼接字符串来显示一个查询非常的麻烦,有一个控件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的更多相关文章

  1. 将开始我的WebForm控件开发之旅

    时间总是过得很快,一转眼三个月就过去了,三个月内发生了很多的事.因为学校的学习,离开了我入门WPF的公司:开发了第一个外包项目,做的是WebForm的:而且了马上要毕业了,毕业后的公司应该是专门用We ...

  2. WebForm控件多字段绑定

    一.这里的多字段绑定是什么意思? 多字段绑定控件其实就是把两个字段显示在一起作为一个字段现在控件上! 可能读者看了可能还是有点懵逼,说的还是比较抽象!的确,光从这上面的确是无法具体到某特定一种情况!那 ...

  3. 从数据库中,绑定JQuery Accordion控件---Repeater control

    http://aspsnippets.com/Articles/jQuery-Accordion-example-in-ASPNet-using-C-and-VBNet.aspx 1. 添加JQuer ...

  4. WebForm 控件(二)

    控件 Calendar:日历控件 但是html代码量太大不适用 FileUpdate: 文件上传 HiddenField:隐藏域 Image: 图片  可以直接给URL 不适用可用html代码写 Ta ...

  5. WebForm 控件(一)、连接数据库

    一.控件 [简单控件] (一)文字显示 1.Label → 在html中相当于span  <asp:Label ID="控件名 runat="server" Tex ...

  6. {Repeater控件} Repeater控件的用法流程及实例

    一.Repeater控件的用法流程及实例: 1.首先建立一个网站,新建一个网页index.aspx. 2.添加或者建立APP_Data数据文件,然后将用到的数据库文件放到APP_Data文件夹中. 3 ...

  7. webform控件

    简单控件: 1.Label 会被编译成span标签 属性: Text:文本内容 CssClass:CSS样式 <asp:Label ID=" CssClass="aaa&qu ...

  8. WebForm控件--2016年12月29日

    简单控件 1.Label  =>   <span id="Label1">Label1</span> 2.Literal  =>  Text 填 ...

  9. 常用的WebForm 控件

    首先回忆一下Html页中的12个表单元素 .文本类 文本框 <input type="text" id="" name="" valu ...

随机推荐

  1. Alpha阶段第十次Scrum Meeting

    情况简述 Alpha阶段第十次Scrum Meeting 敏捷开发起始时间 2016/11/3 00:00 敏捷开发终止时间 2016/11/4 00:00 会议基本内容摘要 详细定义了API接口,汇 ...

  2. /etc/fstab 文件配置项简单介绍

    Untitled .note-content {font-family: 'Helvetica Neue', Arial, 'Hiragino Sans GB', STHeiti, 'Microsof ...

  3. sql 从一个库中取某个表的数据导入到另一个库中相同结构的表中

    sql 2008 从一个库中把 某个表中的数据导入到另一个库中的具有相同结构的表中 use 库1 go insert into  库1.dbo.表1  select * from  库2.dbo.表1 ...

  4. SDL 1.2.15 issue

    SDL 1.2.15中,对于X11的函数,默认采用动态加载的方式 但相应的X11函数名在SDL中并没有重新命名(SDL2中都添加了前缀X11_) 这样在SDL与其他库混合静态编译链接时,X11的函数就 ...

  5. WinForm------GridControl单元格内容修改外表样式

    private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDra ...

  6. 数据存储_ SQLite (1)

    一.SQL语句 如果要在程序运行过程中操作数据库中的数据,那得先学会使用SQL语句 1.什么是SQL SQL(structured query language):结构化查询语言 SQL 是一种对关系 ...

  7. HTML5的属性

    一.全局属性 1.class属性 class属性对元素指定CSS类选择器 <!doctype html> <html> <meta charset="utf-8 ...

  8. marquee标签,好神奇啊...

    <html><body><div style="height:190; margin-top:10; margin-bottom:10; width:96%; ...

  9. java运行过程

    一.安装环境 大家在开发Java的时候,首先回装一个java的开发环境,一个JDK(也包含了JRE),然后设置环境变量,这个过程我就不细说了,大家装完后有没有发现,在装完这个环境的同时在安装JRE,在 ...

  10. sql 比模糊查询速度快的查询方法

    INSTR方法: 1:查询TM不包括大学的所有结果集 SELECT TM, ID FROM X_1459307704859 WHERE instr(TM, '大学') = 0; 2:查询TM所有包含大 ...