如何在Repeater里操作Container.ItemIndex

ASP.NET控件(23)
出处:http://www.yc-edu.org/netpeixun/2558.html
/emilyhyj/archive//1794803.html
Repeater是经常用的一个显示数据集的数据控件,经常我们希望在数据前显示数据的序号,那么我们该怎么为Repeater控件添加序号呢?下面编辑为大家介绍几种常用的为Repeater控件添加序号的方法:
利用Container.ItemIndex属性,代码如下:
&Itemtemplate &
&%# Container.ItemIndex + 1% &
&/Itemtemplate &
利用Repeater的Items.Count属性,代码如下:
&Itemtemplate &
&%# this.Repeater.Items.Count + 1% &
&/Itemtemplate &
利用JS在前台给一个Label标签赋值,代码如下:
在.aspx中添加一个Label控件,用来显示序号。
&Label ID=&label& runat=&server& &&/Label &
&body onload=&show()& &
&Script Language=&javascript& &
function show()
var bj = document.all.tags(&Label经解释后生成的Html标签&);
for (i=0;i&obj.i++)
document.all[&Label经解释后生成的Html标签&][i].innerHTML=i+1;
&/script &
该方法需注意的地方比较多,不推荐使用。
&方法四:在后台中实现,代码如下:
在.aspx里添加一个Label控件
&asp:Label id=&Label1& runat=&server& &&/asp:Label &
在.cs里添加代码:
void InitializeComponent()
&& this.Repeater1.ItemDataBound += new System.Web.UI.WebControls.RepeaterItemEventHandler(this.Repeater1_ItemDataBound);
&& this.Load += new System.EventHandler(this.Page_Load);
void Repeater1_ItemDataBound(object source, System.Web.UI.WebControls.RepeaterItemEventArgs e)
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
&&& ((Label)e.Item.FindControl(&Label1&)).Text = Convert.ToString(e.Item.ItemIndex + 1);
方法五:为Repeater控件添加连续的编号,翻页后序号接前上一页的序号,代码如下:
&%# Container.ItemIndex + 1 + (this.AspNetPager.CurrentPageIndex -1)*每页的数据数量 &
关于给Repeater控件里添加序号的5种方法的内容已经由的讲师为您介绍完了,希望本文的内容能够对学员们有所帮助。
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:170735次
积分:3017
积分:3017
排名:第10746名
原创:97篇
转载:81篇
(3)(1)(1)(2)(1)(3)(1)(1)(1)(6)(3)(1)(4)(5)(2)(3)(3)(6)(8)(1)(6)(12)(5)(23)(9)(2)(7)(20)(24)(21)(21)(17)(5)Container.ItemIndex 获取到行的序号_ASP.NET技巧_动态网站制作指南
Container.ItemIndex 获取到行的序号
来源:人气:2298
Container.ItemIndex 获取到行的序号如果在.net中应用了Repeater、Gridview,想获取到行的序号,很简单,使用Container.ItemIndex即可。在Gridview中使用&%# Container.DataItemIndex %&取得当前行的序号而在Repeater控件中使用Container.ItemIndex取得当前行的序号,主要格式, Container.ItemIndex 用于绑定中的。看例子:&asp:Repeater ID="Repeater1" runat="server"& &ItemTemplate& &%# Container.ItemIndex %& &/ItemTemplate& &/asp:Repeater&
优质网站模板类似问题 &
ASP.NET &&&&最新内容
ASP.NET &&&&相关内容在Repeater 使用&%# Container.ItemIndex + 1%&显示1,2,3,4 - 台州学院数信学生会的日志,人人网,台州学院数信学生会的公共主页
在Repeater 使用&%# Container.ItemIndex + 1%&显示1,2,3,4
在Repeater 使用&%# Container.ItemIndex + 1%&显示1,2,3,4,5,6...顺序&
&asp:Repeater ID="JobList" runat="server"&
&&&&&&&&&&&&&&&&&&&&&&&&&&& &HeaderTemplate&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&& &/HeaderTemplate&
&&&&&&&&&&&&&&&&&&&&&&&&&&& &ItemTemplate&
&&&&&&&&&&&&&&&&&&&&&&&&&&...
阅读(4184)|
人人移动客户端下载下面看一个简单的例子学习使用repeater实现新增多条记录的功能
&style type="text/css"&
background-color:white;
border:1px solid #0094ff;
margin:<span style="color: #px auto;
width:<span style="color: #px;
border-collapse:collapse;
#tbList td,th{
background-color:white;
border:2px solid #0094ff;
padding:5px;
&asp:ScriptManager runat="server" ID="SM" EnablePartialRendering="true"&
&/asp:ScriptManager& 这个是为了实现新增多条记录时实现无刷新!
&table id="tbList"&
&td colspan="7"&
&asp:UpdatePanel ID="updatePanel1" runat="server"&
&ContentTemplate&
&asp:Button ID="addEquipmentBtn" runat="server" Text="新增" OnClick="AddEquipment_Click"/&
&asp:Repeater ID="rptInstallationEquipment" runat="server" OnItemCommand="rptInstallationEquipment_ItemCommand" OnItemDataBound="rptInstallationEquipment_ItemDataBound"&
&HeaderTemplate&
&table id="tblInstallationEquipment" width="100%"&
&/HeaderTemplate&
&ItemTemplate&
&td class="bg nowidth"&
&asp:Label runat="server" ID="EquipmentSortOrder" Text='&%#Container.ItemIndex + 1%&'&&/asp:Label&
&td class="bg nowidth"&
&asp:DropDownList runat="server" ID="EquipmentType" &
&asp:ListItem Value="lanwhy"&lanwhy&/asp:ListItem&
&asp:ListItem Value="8023"&8023&/asp:ListItem&
&/asp:DropDownList&
&td class="bg nowidth"&
&asp:TextBox ID="FaultDateTime" Text='&%#Eval("FaultDateTime") %&'
isAddRedStar="false" runat="server" validator="required,pattern[date]"&
&/asp:TextBox&
&td class="bg nowidth"&
&asp:TextBox runat="server" ID="DetailContent" Text='&%#Eval("DetailContent") %&'
MaxLength="1000" TextMode="MultiLine" validator="length[1,1000]"&&/asp:TextBox&
&td class="bg nowidth"&
&asp:TextBox runat="server" ID="FaultSortOrder" Text='&%#Eval("FaultSortOrder") %&' &&/asp:TextBox&
&td class="bg nowidth"&
&asp:TextBox runat="server" ID="Result" Text='&%#Eval("Result") %&' MaxLength="1000" TextMode="MultiLine" validator="length[1,1000]"&&/asp:TextBox&
&td class="bg nowidth"&
&asp:Button ID="btnDelete" runat="server" Text="删除" CommandName="EquipmentDeleteInfo"
CommandArgument='&%#Container.ItemIndex + 1%&' /&
&asp:HiddenField runat="server" ID="hidInstallationEquipmentID" Value='&%#Eval("InstallationEquipmentID") %&' /&
&/ItemTemplate&
&FooterTemplate&
&/FooterTemplate&
&/asp:Repeater&
&/ContentTemplate&
&/asp:UpdatePanel&
添加设施设备
也就是新增按钮的点击事件
protected void AddEquipment_Click(object sender, EventArgs e)
DataTable dt = this.CopyFormDetailData();
DataRow dr = dt.NewRow();
dt.Rows.Add(dr);
ViewState.Add("EquipmentData", dt);
DetailDataBinds();
protected DataTable CopyFormDetailData()
if ((ViewState["EquipmentData"] as DataTable) == null)
DataTable dtView = new DataTable();
dtView.Columns.Add("InstallationEquipmentID", typeof(string));
dtView.Columns.Add("EquipmentCode", typeof(string));
dtView.Columns.Add("EquipmentName", typeof(string));
dtView.Columns.Add("FaultDateTime", typeof(string));
dtView.Columns.Add("DetailContent", typeof(string));
dtView.Columns.Add("FaultSortOrder", typeof(string));
dtView.Columns.Add("Result", typeof(string));
dtView.Rows.Add(dtView.NewRow());
ViewState.Add("EquipmentData", dtView);
DataTable dt = (ViewState["EquipmentData"] as DataTable).Clone();
foreach (RepeaterItem ri in this.rptInstallationEquipment.Items)
DataRow dr = dt.NewRow();
dr["InstallationEquipmentID"] = (ri.FindControl("hidInstallationEquipmentID") as HiddenField).V
dr["EquipmentCode"] = (ri.FindControl("EquipmentType") as DropDownList).SelectedV
dr["EquipmentName"] = (ri.FindControl("EquipmentType") as DropDownList).SelectedItem.T
dr["FaultDateTime"] = (ri.FindControl("FaultDateTime") as TextBox).T
dr["DetailContent"] = (ri.FindControl("DetailContent") as TextBox).T
dr["FaultSortOrder"] = (ri.FindControl("FaultSortOrder") as TextBox).T
dr["Result"] = (ri.FindControl("Result") as TextBox).T
dt.Rows.Add(dr);
protected void DetailDataBinds()
DataTable dt = ViewState["EquipmentData"] as DataT
rptInstallationEquipment.DataSource =
rptInstallationEquipment.DataBind();
删除设施设备数据
protected void rptInstallationEquipment_ItemCommand(object sender, RepeaterCommandEventArgs e)
if (e.CommandName == "EquipmentDeleteInfo")
DataTable dt = new DataTable();
dt = this.CopyFormDetailData();
dt.Rows.RemoveAt(e.Item.ItemIndex);
this.rptInstallationEquipment.DataSource =
this.rptInstallationEquipment.DataBind();
int cnt = this.rptInstallationEquipment.Items.C
if (cnt & 0)
((Button)this.rptInstallationEquipment.Items[cnt - 1].FindControl("btnDelete")).Focus();
this.addEquipmentBtn.Focus();
绑定设施设备数据
protected void rptInstallationEquipment_ItemDataBound(object sender, RepeaterItemEventArgs e)
{ //因为专业和处理结果每次新增新行时都会有默认值,不做处理的话会把上一行的数据覆盖
TextBox txtResult = (TextBox)e.Item.FindControl("Result");
if (txtResult != null)
txtResult.Text = "未修复";
DataRowView drv = (DataRowView)e.Item.DataI
if (!string.IsNullOrWhiteSpace(drv["Result"].ToString()))
txtResult.Text = drv["Result"].ToString();
DropDownList dropEquipmentType = (DropDownList)e.Item.FindControl("EquipmentType");
if (dropEquipmentType != null)
dropEquipmentType.DataBind();
DataRowView drv = (DataRowView)e.Item.DataI
//保持下拉框选择的项
if (!string.IsNullOrWhiteSpace(drv["EquipmentName"].ToString()))
dropEquipmentType.Items.FindByText(drv["EquipmentName"].ToString()).Selected = true;
可以看出,第一次点击新增时,增加了序号为1的行,输入数据后,再次点击新增按钮,发现序号1的行的数据还是会保持!
之前没接触这种用法时,可以用JavaScript或者JQuery实现这种新增多行的需求,当进行项目开发时,学会了这种,可以很容易实现这种需求,快捷完成增删改查!
点击删除按钮可以删除整行
下面简单介绍下使用JQuery的方式实现增加多条记录
&th class="thTitle" colspan="10" style="text-align: left"&
近期工作安排
&input type="button" onclick="addSecurity()" value="增加"
&td colspan="10"&
&table width="100%" class="formitem" id="tabSecurity"&
&th style="text-align: width: 40px"&
&th style="text-align: width: 40%;"&
&th style="text-align: width: 30%;"&
&th style="text-align: width: 20%;"&
&th style="text-align: width: 55px"&
//增加近期工作安排
function addSecurity() {
var trNum = $("#tabSecurity tr").
var html = '&tr&';
html += '&td&' + trNum + '&/td&';
html += '&td&&textarea validator="required,length[1,2000]" class="textareaAutoHeight"&&/textarea&&/td&';
html += '&td&&textarea validator="required,length[1,2000]" class="textareaAutoHeight"&&/textarea&&/td&';
html += '&td&&input type="hidden" /&&textarea validator="required"
class="textareaAutoHeight"&&/textarea&&/td&';
html += '&td&&input type="button" onclick="deleteSecurity(this)" class="com_b" value="删除" /&&/td&';
html += '&/tr&';
$("#tabSecurity").append(html);
//tabSecurity.ResetHeight();
function deleteSecurity(_this) {
$(_this).parent().parent().remove();
$("#tabSecurity tr").each(function (index, element) {
if (index & 0) {
$(this).find('td').eq(0).html(index);
function getItemDetail() {
var resultArray = [];
$("#tabSecurity tr").each(function (index, element) {
if (index & 0) {
var entity = {};
entity.ORDER = $(this).children().eq(0).html();
entity.EVENTNOTE = $(this).children().eq(1).children().eq(0).val();
entity.DealProposal = $(this).children().eq(2).children().eq(0).val();
entity.RESORGIDS = $(this).children().eq(3).children().eq(0).val();
resultArray.push(entity);
return resultA
如何获取repeater中多行数据?
List&InstallationEquipmentInfo& listInstallationEquipmentInfo = new List&InstallationEquipmentInfo&();
foreach (Control record in this.rptInstallationEquipment.Items)
InstallationEquipmentInfo installationEquipmentInfo = new InstallationEquipmentInfo();
installationEquipmentInfo.EquipmentCode = ((DropDownList)record.FindControl("EquipmentType")).SelectedV
installationEquipmentInfo.EquipmentName = ((DropDownList)record.FindControl("EquipmentType")).SelectedItem.T
installationEquipmentInfo.EquipmentSortOrder = ((Label)record.FindControl("EquipmentSortOrder")).T
installationEquipmentInfo.DetailContent = ((TextBox)record.FindControl("DetailContent")).T
installationEquipmentInfo.FaultDateTime = ((TextBox)record.FindControl("FaultDateTime")).Text.ToString();
installationEquipmentInfo.FaultSortOrder = ((TextBox)record.FindControl("FaultSortOrder")).T
installationEquipmentInfo.Result = ((TextBox)record.FindControl("Result")).T
listInstallationEquipmentInfo.Add(installationEquipmentInfo);
阅读(...) 评论()}

我要回帖

更多关于 手工树叶制作大全图片 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信