1.用Repeater绑定了一列数据
2.联系方式一列处隐藏了一个加载了联系方式div
3.当点击查看时则显示隐藏的div
在遇到这个问题的时候思想走到了误区
错误的想法:首先认为在前台.aspx文件中放了一个服务器端的空间div
在绑定数据的时候循环出来N个div
我只是击查看地址的时候只是让某一个div显示而已 如果我直接在ItemCommand事件获取div控件并设置div显示的话会让整个一列的div都显示
所以在.cs文件中写了这样一段代码
protected
void
Repeater1_ItemCommand(
object
source, RepeaterCommandEventArgs e)
{
RepeaterItem item = Repeater1.Items[e.Item.ItemIndex] as RepeaterItem;
HtmlControl div = item.FindControl( " divAddress " ) as HtmlControl;
divAddress.Visible = true ;
}
{
RepeaterItem item = Repeater1.Items[e.Item.ItemIndex] as RepeaterItem;
HtmlControl div = item.FindControl( " divAddress " ) as HtmlControl;
divAddress.Visible = true ;
}
其实只需要和平常的在绑定控件中获取服务器控件一样
protected
void
Repeater1_ItemCommand(
object
source, RepeaterCommandEventArgs e)
{
HtmlControl divAddress = e.Item.FindControl( " divAddress " ) as HtmlControl;
divAddress.Visible = true ;
}
{
HtmlControl divAddress = e.Item.FindControl( " divAddress " ) as HtmlControl;
divAddress.Visible = true ;
}
ItemCommand事件 当单击 Repeater 控件中的任一按钮时触发。
当点击查看地址时 ItemCommand事件被触发 你点击的那一行的div的Visible属性设置true