Repeater数据绑定

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="WebApplication1.Index" %> <!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">
.style1
{
width: 100%;
}
.style2
{
width: 254px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div> <table class="style1">
<tr>
<td class="style2">
<ul>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<li>
<%#Eval("name") %>
<hr />
<asp:HiddenField ID="HiddenField1" Value='<%# Eval("id") %>' runat="server" />
<ul>
<asp:Repeater ID="Repeater2" runat="server">
<ItemTemplate>
<li>
<asp:LinkButton ID="LinkButton1" CommandArgument='<%#Eval("id") %>' OnClick="ShowList" runat="server"><%# Eval("Name") %></asp:LinkButton>
</li>
</ItemTemplate>
</asp:Repeater>
</ul> </li>
</ItemTemplate>
</asp:Repeater>
</ul>
</td>
<td>
<asp:DataList ID="DataList1" runat="server" RepeatColumns="4">
<ItemTemplate>
<table class="style1">
<tr>
<td>
<asp:Image ID="Image2" runat="server" Height="120px"
ImageUrl='<%# Eval("pic") %>' Width="100px" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("name") %>'></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</td>
</tr>
</table> </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 WebApplication1
{
public partial class Index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindList();
} } private void BindList()
{
string sql = "select * from goodClass where pid=0";
Repeater1.DataSource = SQLHelper.GetTable(sql);
Repeater1.DataBind();
foreach ( RepeaterItem item in Repeater1.Items)
{
string id = (item.FindControl("HiddenField1") as HiddenField).Value;
Repeater p2 = item.FindControl("Repeater2") as Repeater;
string s2 = "select * from goodClass where pid=" + id;
p2.DataSource = SQLHelper.GetTable(s2);
p2.DataBind();
}
} public void ShowList(object sender, EventArgs e)
{
LinkButton lb = sender as LinkButton;
string id = lb.CommandArgument;
Response.Write("查询类别:" + id + "对应的商品");
string sql = "select * from goods where cid=" + id;
DataList1.DataSource = SQLHelper.GetTable(sql);
DataList1.DataBind(); }
}
}
Repeater数据绑定的更多相关文章
- Repeater数据绑定和操作
Repeater使用详细指南 ASP.NET WebForm开发中尽量少用系统提供的runat="server"的服务器控件,尤其像GridView之类的“重量级”武器,自动生成的 ...
- Repeater 控件使用总结
关于Repeater控件使用的一些总结,希望能对将来有机会看到这篇日志的同事有所帮助.也是为了在自己开发有所遗忘的时候能够参考一下.前言:Repeater是一个迭代控件,什么是迭代控件呢?书本上的 ...
- PagedDataSource数据绑定控件和AspNetPager分页控件结合使用列表分页
1.引用AspNetPager.dll. 2.放置Repeater数据绑定控件. <asp:Repeater ID="Repeater1" runat="serve ...
- webform组合查询和分页
1.组合查询(1)数据访问类 //参数1:SQL语句 参数2:哈希表public List<Users> chas(string s,Hashtable has) { List<Us ...
- asp.net导出Excel 按照预定格式,以及解决导出乱码
protected void ToExcel() { //新建一个Gridview,原因:避免当前窗口GridView外层没有直接跟form标签,从而避免“gridview1未包含在run='serv ...
- ASP.NET控件的ID,ClientID,UniqueId的区别
一般情况下三者相同(没有父控件) ID:获取或设置分配给服务器控件的编程标识符.分配给控件的编程标识符. (可写) 设置服务器控件上的此属性可提供对服务器控件的属性.事件和方法的编程访问.Web 开发 ...
- 数据绑定控件之Repeater
引言 前几篇的文章在说AJAX的内容,利用AJAX技术能够开发出高效运行的网站应用程序,不过在进行B/S项目开发时只拥有AJAX技术是远远不够的,踏入到B/S要学的东西会更多,但相较C/S的复杂逻辑结 ...
- DataItem,gridview,repeater数据控件数据绑定
Container.DataItem几种方式. 在绑定数据时经常会用到这个句程序:<%# DataBinder.Eval(Container.DataItem,"xxxx") ...
- Repeater实现数据绑定
Repeater基础 在aspx文件中加入Repeater 控件,在<ItemTemplate></ItemTemplate>包含的范围里加入自己控制的代码,需要替换的变量使用 ...
随机推荐
- backend flow
在PD之后,netlist中会多出很多DCAP元件(去耦电容,减少IR-Drop)或者filter cell(保证芯片均匀度要求) 还有一些antenna cell也就是一些diode用来泻流,防止天 ...
- PAT乙级 1029. 旧键盘(20)
1029. 旧键盘(20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 旧键盘上坏了几个键,于是在敲一段文字的 ...
- [Ubuntu] Linux下使用google app engine,无法打开https网站的解决方法
为什么这里写的是 google app engine?原因我就不解释了.步骤如下: 1)安装证书导入工具:$ sudo apt-get install libnss3-tools 2)导入CA.crt ...
- archlinux 网络配置
https://wiki.archlinux.org/index.php/Network_configuration_%28%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87%2 ...
- struct2 学习总结
花了近半个月学习了struct2.现大致总结下学习点: 1. struct2 入门以及基本配置(未继承ActionSupport,配置struts.xml文件,execute方法直接返回SUCESS) ...
- zw版【转发·台湾nvp系列Delphi例程】HALCON SmoothImage
zw版[转发·台湾nvp系列Delphi例程]HALCON SmoothImage procedure TForm1.Button1Click(Sender: TObject);var image0, ...
- Hadoop之TaskInputOutputContext类
在MapReduce过程中,每一个Job都会被分成若干个task,然后再进行处理.那么Hadoop是怎么将Job分成若干个task,并对其进行跟踪处理的呢?今天我们来看一个*Context类——Tas ...
- 什么是商业智能BI和实施BI的解决方案【转】
商业智能,或BI,是一种统称,泛指用于对一个企业的原始数据进行分析的各种各样的软件系统.商业智能(BI)是由若干相关的活动组成的领域,包括数据挖掘,在线分析处理,查询和报表. 企业用商业智能(BI)来 ...
- 5 Best Automation Tools for Testing Android Applications
Posted In | Automation Testing, Mobile Testing, Software Testing Tools Nowadays automated tests ar ...
- PHP上传文件详解 错误提示
首先在php.ini里配置上载文件.有以下几个重要的配置单: 选项 默认值 说明 post_max_size 8M 控制以后的POST请求的最大规模.必须大于upload_max_filesize选项 ...