ASP.NET repeater method to add ordinal columns
- 2020-05-17 05:19:07
- OfStack
In the process of project development, we will often encounter ASP.NET repeater control to add serial number column, some novices may not be able to do so. We have collected some on the Internet, and you can refer to them if you need them
ASP.NET repeater method to add ordinal columns
1. < itemtemplate >
< tr > < td >
< %# Container.ItemIndex + 1% >
< /td > < /tr >
< /itemtemplate >
2, < itemtemplate >
< tr > < td >
< %# this.rpResult.Items.Count + 1% >
< /td > < /tr >
< /itemtemplate >
3, in < form > < /form > add < Label ID="dd" > < /Label >
< body nload="show()" >
< Script. Language="JScript" >
function show()
{
var bj = document.all.tags("LABEL");
for (i=0;i < obj.length;i++)
{
document.all["dd"][i].innerHTML=i+1;
}
}
< /script >
4. Background implementation method:
Add it to.aspx < asp:Label id="Label1" Runat="server" > < /asp:Label >
I'm going to add it in.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);
}
}
Add html according to the condition
< %#Container.ItemIndex == 8 ? " < br > < a href = 'http://www.ginchan.com.tw/' target='_blank' > < img style='width:338px;heigh:70px' src='/ImportAD/ADmid.gif' > < /a > " : ""% >
ASP.NET repeater method to add ordinal columns
1. < itemtemplate >
< tr > < td >
< %# Container.ItemIndex + 1% >
< /td > < /tr >
< /itemtemplate >
2, < itemtemplate >
< tr > < td >
< %# this.rpResult.Items.Count + 1% >
< /td > < /tr >
< /itemtemplate >
3, in < form > < /form > add < Label ID="dd" > < /Label >
< body nload="show()" >
< Script. Language="JScript" >
function show()
{
var bj = document.all.tags("LABEL");
for (i=0;i < obj.length;i++)
{
document.all["dd"][i].innerHTML=i+1;
}
}
< /script >
4. Background implementation method:
Add it to.aspx < asp:Label id="Label1" Runat="server" > < /asp:Label >
I'm going to add it in.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);
}
}
Add html according to the condition
< %#Container.ItemIndex == 8 ? " < br > < a href = 'http://www.ginchan.com.tw/' target='_blank' > < img style='width:338px;heigh:70px' src='/ImportAD/ADmid.gif' > < /a > " : ""% >