濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > Repeater與ListView功能概述及使用介紹

Repeater與ListView功能概述及使用介紹

熱門標(biāo)簽:百度ai地圖標(biāo)注 預(yù)測(cè)式外呼系統(tǒng)使用說明 蘋果手機(jī)凱立德地圖標(biāo)注 南陽(yáng)外呼系統(tǒng)定制化 合肥電銷外呼系統(tǒng)哪家公司做的好 電話機(jī)器人軟件銷售工作 申請(qǐng)400電話手續(xù) 玉林市機(jī)器人外呼系統(tǒng)哪家好 同安公安400電話怎么申請(qǐng)流程

Repeater

Repeater(foreach)用于對(duì)綁定數(shù)據(jù)源中的數(shù)據(jù)進(jìn)行遍歷并按格式顯示,每條數(shù)據(jù)以什么格式顯示是由Repeater的ItemTemplate>來(lái)決定的,模板會(huì)多次顯示,就像foreach, ItemTemplate 中相當(dāng)于{}中的語(yǔ)句。ItemTemplate>姓名:%#Eval(“Name”)%>b>年齡:%#Eval(“Age”)%>/b>br />/ItemTemplate>。注意:%和#中間不能有空格。

%#Eval("Name")%>表示在這個(gè)位置顯示當(dāng)前實(shí)體對(duì)象的Name屬性,注意調(diào)用Eval、Bind這些數(shù)據(jù)綁定方法的時(shí)候要用#。

因?yàn)镋val就是將屬性顯示到指定的位置,因此也可以顯示到文本框中ItemTemplate>姓名:
asp:TextBox runat="server"Text='%#Eval("Name") %>' />
/ItemTemplate>

注意不要寫成Text="%#Eval('Name')%>" 因?yàn)?%>中的是C#代碼,''是字符,而不是字符串

還可以用在服務(wù)器控件中asp:TextBox Text='%#Eval("Name") %>'runat="server">/asp:TextBox>

DemoCode及注意點(diǎn)
Repeater.aspx

復(fù)制代碼 代碼如下:

% @ Page Language="C#" AutoEventWireup="true" CodeBehind="Repeater.aspx.cs" Inherits ="WebForm.Repeater" %>
! 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">
#tblist{ border-top :1px solid #000 ; border-left : 1px solid #000 ; margin: 0px auto ;width : 600px;}
#tblist td {border-bottom : 1px solid #000 ; border-right: 1px solid #000; padding :5px }
#didPanel {position : absolute; left :350px ; top: 200px ;width : 500px; height :70px ; border: 1px solid #000; background-color :Window ; padding: 15px ;display : none}
/style >
/ head>
body>
form id="form1" runat="server">
asp : ObjectDataSource ID ="ObjectDataSource1" runat ="server"
SelectMethod ="getAllClasses" TypeName ="BLL.Classes">
SelectParameters>
asp: Parameter DefaultValue ="false" Name ="isDel" Type ="Boolean" />
/ SelectParameters>
/asp : ObjectDataSource>
div >
table id="tbList">
asp: Repeater ID ="Repeater1" runat ="server" DataSourceID ="ObjectDataSource1">
HeaderTemplate> !--頭模板-->
tr>
td> ID /td >
td> Name /td >
td> Count /td >
td> Img /td >
td> 操作 /td >
/ tr>
/ HeaderTemplate>
ItemTemplate> !--項(xiàng)模板-->
tr>
td> input type ="text" value =" %# Eval("CID")%> " />/ td >
td>
asp: TextBox ID ="TextBox1" runat ="server" Text ='% # Eval("CName")%> '>/asp : TextBox>/ td >
td> % #Eval( "CCount" )%> /td >
td>
%--img src="images/%#Eval("CImg")%>" style="width:100px;height:80px;"/>--%>
!--服務(wù)器端圖片路徑需要添加images/文件路徑時(shí) 需要放在#號(hào)后 如果images/《% 會(huì)導(dǎo)致《%被作為字符串解析-->
asp: Image ID ="Image1" runat ="server" ImageUrl ='% # "images/"+Eval("CImg")%> ' Width ="100px" Height ="80px"/>
!--補(bǔ)充:模板中的按鈕一般不寫OnClick事件響應(yīng),而是響應(yīng)Repeater的ItemCommand事件。-->
/ td>
/ tr>
/ ItemTemplate>
SeparatorTemplate> !--兩項(xiàng)數(shù)據(jù)間的間隔模板-->
tr>
td colspan ="5" style ="background-color :red; height:2px; line-height :3px;">/td >
/ tr>
/ SeparatorTemplate>
AlternatingItemTemplate> !--交替項(xiàng)模板-->
tr style ="background-color :Gray">
td> input type ="text" value =" %# Eval("CID")%> " />/ td >
td>
asp: TextBox ID ="TextBox1" runat ="server" Text ='% # Eval("CName")%> '>/asp : TextBox>/ td >
td> % #Eval( "CCount" )%> /td >
td> % #Eval( "CImg" )%> /td >
td>
asp: Button ID ="btnDel" runat ="server" Text ="刪除" OnCommand ="Button_OnClick" CommandName ="Del" CommandArgument ='% # Eval("CID")%> '/>
/ td>
/ tr>
/ AlternatingItemTemplate>
FooterTemplate> !--腳模板-->
tr>
td colspan ="5">不是所有痞子都叫一毛 / td>
/ tr>
/ FooterTemplate>

/ asp: Repeater >
/table >
/div >
/form >
/ body>
/ html>

Repeater.aspx.cs
復(fù)制代碼 代碼如下:

using System;
using System.Web.UI.WebControls;
namespace WebForm {
public partial class Repeater : System.Web.UI. Page {
protected void Page_Load( object sender, EventArgs e) {
}
protected void Button_OnClick( object sender, CommandEventArgs e) {
//Response.Write("CommandArgument" + e.CommandArgument + "CommandName" + e.CommandName + "刪除了" + DateTime.Now);需前臺(tái)設(shè)置CommandArgument及CommandName屬性
if (new BLL. Classes().SoftDel( Convert .ToInt32(e.CommandArgument)) > 0) {
Response.Write( "刪除成功" );
Repeater1.DataBind(); //重新綁定數(shù)據(jù) 否則服務(wù)器不會(huì)重新生成Repeater數(shù)據(jù) 而是返回__VIEWSTATE中原有數(shù)據(jù)
} else {
Response.Write( "刪除失敗" );
}
}
}
}

效果圖:

ListView

Repeater一般只用來(lái)展示數(shù)據(jù),如果要增刪改查(CRUD)則用ListView更方便。使用向?qū)?lái)使ListView會(huì)自動(dòng)生成很多模板,免去手寫模板代碼的麻煩,必要時(shí)進(jìn)行手工調(diào)整即可。

 同Repeater一樣設(shè)定數(shù)據(jù)源,然后點(diǎn)擊智能提示中的“配置ListView”,選擇一種布局和樣式,然后根據(jù)需要勾選“啟用編輯”、“啟用刪除”、“啟用插入”、“啟用分頁(yè)”,就會(huì)自動(dòng)生成常用的模板。

效果圖類似:

ListView默認(rèn)的分頁(yè)是先從數(shù)據(jù)源取得所有數(shù)據(jù),然后再截取當(dāng)前頁(yè)面的部分,在數(shù)據(jù)量非常大的情況下效率非常低,因此默認(rèn)分頁(yè)基本不能用。應(yīng)該是只從數(shù)據(jù)源取得要顯示的數(shù)據(jù)。詳見下章《如何實(shí)現(xiàn)ListView高效分頁(yè)》

同樣內(nèi)容點(diǎn)可參見《如何實(shí)現(xiàn)ListView高效分頁(yè)》貼出的代碼

LayoutTemplate為布局模板,布局模板中必須有一個(gè)ID為itemPlaceholder的服務(wù)端控件,項(xiàng)占位符(FrameWork4.0以后不需要),itemPlaceholder前面就是相當(dāng)于Repeater中的HeaderTemplate,itemPlaceholder后面就是相當(dāng)于Repeater中的FooterTemplate,因此ListView中沒有這兩個(gè)模板。

ItemTemplate是每一項(xiàng)的模板,AlternatingItemTemplate是隔行顯示的模板,和Repeater一樣。

EmptyDataTemplate為數(shù)據(jù)源沒有數(shù)據(jù)的時(shí)候顯示的內(nèi)容(Insert也算數(shù)據(jù)),這樣的話可以實(shí)現(xiàn)“沒有查找結(jié)果”、“對(duì)不起,找不到您要找的數(shù)據(jù)”等提示內(nèi)容

InsertItemTemplate為插入數(shù)據(jù)界面的模板,

EditItemTemplate為編輯數(shù)據(jù)的模板,

SelectedItemTemplate為標(biāo)記為Selected的行的模板。

數(shù)據(jù)源配置見上章 Asp.Net中的數(shù)據(jù)源

您可能感興趣的文章:
  • Repeater的FooterTemplate顯示某列總計(jì)思路與代碼
  • Repeater控件動(dòng)態(tài)變更列(Header,Item和Foot)信息實(shí)現(xiàn)思路
  • repeater 分列顯示以及布局的實(shí)例代碼
  • Repeater對(duì)數(shù)據(jù)進(jìn)行格式化處理
  • Repeater全選刪除和分頁(yè)實(shí)現(xiàn)思路及代碼
  • ASP.NET中repeater嵌套實(shí)現(xiàn)代碼(附源碼)
  • Repeater控件數(shù)據(jù)導(dǎo)出Excel(附演示動(dòng)畫)
  • asp.net中讓Repeater和GridView支持DataPager分頁(yè)
  • 在jquery repeater中添加設(shè)置日期,下拉,復(fù)選框等控件
  • Repeater控件動(dòng)態(tài)變更列(Header,Item和Foot)信息(重構(gòu)cs)

標(biāo)簽:南京 南昌 海南 南京 揚(yáng)州 嘉興 淄博 臺(tái)州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Repeater與ListView功能概述及使用介紹》,本文關(guān)鍵詞  Repeater,與,ListView,功能,概,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Repeater與ListView功能概述及使用介紹》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于Repeater與ListView功能概述及使用介紹的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    枝江市| 威远县| 山丹县| 博野县| 林州市| 乐东| 华宁县| 满城县| 棋牌| 观塘区| 仲巴县| 富源县| 洛川县| 鹤壁市| 兰西县| 濮阳县| 蓬溪县| 临武县| 舟曲县| 阿坝县| 都江堰市| 靖江市| 交城县| 三台县| 本溪市| 池州市| 万山特区| 塔河县| 昭通市| 舟曲县| 万荣县| 江油市| 余庆县| 南乐县| 盘锦市| 唐山市| 自治县| 泰宁县| 东平县| 宣城市| 鹰潭市|