在数据列表中隐藏控件 [英] Hide control in Datalist
本文介绍了在数据列表中隐藏控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好朋友.
我正在使用一个数据面板,其中它们是一个面板.
我想在数据库列中的值为false时隐藏面板,而在数据库列中为true时显示面板.
请帮助
Hello Friends.
I am using a datalist in which their is a panel.
I want to hide the panel when a value in the database column is false and show the panel when a value in the database column is true.
Please help
推荐答案
使用数据列表中的项目数据绑定事件来实现此功能.您可以使用标签变量或数据键来检查条件列的值,具体取决于是否显示该列.
Use item data bound event in datalist for such functionality. You can use a label variable or datakey to check the value for the conditional column depending on whether to show that column or not.
void Item_Bound(Object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
string strID = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
// Retrieve the Panel control in the current DataListItem.
Panel toBeOrNotToBe = (Label)e.Item.FindControl("myPanel");
if(strID=="something")
// make it hidden here;
}
}
这篇关于在数据列表中隐藏控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文