protected void DataList1_ItemCreated(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Footer)
{
for (int i = 1; i <=pageNum; i++)
{
LinkButton lbtn = new LinkButton();
lbtn.ID = "lbtn" + i.ToString();
lbtn.CommandName = "lbtn" + i.ToString();
lbtn.Text = i.ToString()+" ";
lbtn.Font.Underline = false;
e.Item.Controls.Add(lbtn);
}
}
}
这是datalist添加页码的代码,与datagrid类似
{
if (e.Item.ItemType == ListItemType.Footer)
{
for (int i = 1; i <=pageNum; i++)
{
LinkButton lbtn = new LinkButton();
lbtn.ID = "lbtn" + i.ToString();
lbtn.CommandName = "lbtn" + i.ToString();
lbtn.Text = i.ToString()+" ";
lbtn.Font.Underline = false;
e.Item.Controls.Add(lbtn);
}
}
}
这是datalist添加页码的代码,与datagrid类似
public override void InitializeCell(TableCell cell,
int columnIndex, ListItemType itemType)
{
//let the base class initialize the cell
base.InitializeCell(cell, columnIndex, itemType);
ViewState["_columnIndex"]=columnIndex;
if( itemType == ListItemType.EditItem ||
itemType == ListItemType.Item ||
itemType == ListItemType.AlternatingItem ||
itemType == ListItemType.SelectedItem ||
itemType == ListItemType.Header)
{
CheckBox checkbox = new CheckBox();
//assign an ID that we can use to find the control later
//we don't want to add a normal checkbox to the header.
checkbox.ID = (itemType==ListItemType.Header)? ("checkboxHead"+"_"+columnIndex): ("checkboxCol"+"_"+columnIndex);
if(checkbox.ID==("checkboxHead"+"_"+columnIndex))
checkbox.Attributes.Add("onclick","CheckAll(this)");
else if(checkbox.ID==("checkboxCol"+"_"+columnIndex))
checkbox.Attributes.Add("onclick","CheckChanged(this)");
cell.Controls.Add(checkbox);
}
}