listview练习
namespace ListView
{
public partial class listview练习 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
{
//if (e.Item.ItemType == ListViewItemType.DataItem)//数据项
//{
DataRowView drv = (DataRowView)e.Item.DataItem;
var row = (DataSet1.T_userRow)drv.Row;
if (row.age >= 30)
{
HtmlTableRow tr = (HtmlTableRow)e.Item.FindControl("tr1");
tr.Attributes["class"] = "bgcolor";
}
//}
}
protected void ListView1_ItemCreated(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.InsertItem)//插入项
{
TextBox tb = (TextBox)e.Item.FindControl("ageTextBox");
tb.Text = "20";//设置插入的默认值
}
}
protected void ListView1_ItemInserting(object sender, ListViewInsertEventArgs e)
{
if (e.Values["user"].ToString() == "tom")
{
e.Cancel =true;//取消插入
}
}
}
}