ASP.NET datalist 里的linkbutton 调用

2024-12-20 03:29:10
推荐回答(3个)
回答1:

首先:DataList里面有ItemDataBound个事件,双击这个事件,里面这样写:
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e) //DataList的ItemDataBound事件
{
if (e.Item.ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternatingItem)
{

DataRowView row = (DataRowView)e.Item.DataItem;
//在前台DataList的模板项里定义一个Linkbutton
Linkbutton lb = (Linkbutton )e.Item.FindControl("Linkbutton1");
//Linkbutton1为Linkbutton的ID号
lb.Visible=false;

}
}

回答2:

在datalist的ItemDataBound事件中获取:
protected void datalist1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
linkbutton lb=e.Item.FindControl("控件的id") as linkbutton;
lb.visible=false;
}
手写代码,大小写可能不准确,根据实际情况修改

回答3:

FindControl("控件的id") 用这个查找