这次我从头问,希望给个明白的答案,感谢!(datalist嵌套)
<asp:datalist id= "dlDQue " runat= "server ">
<ItemTemplate>
<table>
//这个table里的是问题并且有个btuuton id= "btnShow " CommandName= "Show "
</table>
<div id= "dv " runat= "server ">
<asp:DataList ID= "dlAnswer " Runat= "server " DataSource= ' <%# GetAnswersById(DataBinder.Eval(Container, "DataItem.DQueId ").ToString())%> ' OnItemCommand= "dlAnswer_ItemCommand ">
</datalist> //这个datalist里是单个问题的所有回答
<table>
//这个table里放的是提交回答的信息和提交按钮
</table>
</div>
</ItemTemplate>
<datalist>
我的问题:如何做到点btnshow按钮,来显示知隐藏div
------解决方案--------------------void Item_Command(Object sender, DataListCommandEventArgs e)
{
if (e.CommandName == "Show ")
{
HtmlGenericControl ctl = e.Item.FindControl( "dv ") as HtmlGenericControl;
ctl.Visible = true;
}
}
------解决方案--------------------在dlAnswer_ItemCommand这个事件里怎么能取到第二个table里的控件
--------------------------
使用dlAnswer.Parent.FindControl方法试试。
------解决方案-------------------- <asp:datalist id= "dlDQue " runat= "server ">
<ItemTemplate>
<table>
//这个table里的是问题并且有个btuuton id= "btnShow " CommandName= "Show " onclick= "javascript:dv <%# Eval( "dlDQue_id ") %> .style.display= 'none '; "
</table>
<div id= "dv <%# Eval( "dlDQue_id ") %> ">
<asp:DataList ID= "dlAnswer " Runat= "server " DataSource= ' <%# GetAnswersById(DataBinder.Eval(Container, "DataItem.DQueId ").ToString())%> ' OnItemCommand= "dlAnswer_ItemCommand ">
</datalist> //这个datalist里是单个问题的所有回答
<table>
//这个table里放的是提交回答的信息和提交按钮
</table>
</div>
</ItemTemplate>
<datalist>
当然,你直接给runat=server的button加上onclick= "javascript:dv <%# Eval( "dlDQue_id ") %> .style.display= 'none '; " ,会出错的.你可以通过数据绑定,在cs代码中,给每一行的该按钮加上这么一个onclick事件
<input type=button onclick= "javascript:div2.style.display= 'none '; " value= "测试 " />
<div id= "div2 ">
abcabcabcabcabcabcabcabcabcabcabc
</div>
------解决方案--------------------只要你的table中的控件都是服务器端控件 根据ID值就能找到 如找Button bt1
则在itemDataBind事件中写:
Button bt= e.Item.FindControl( "tb1 ");
找到的是那一行的button实例
------解决方案--------------------似乎另一帖偶已回答了嘛
------解决方案-------------------- <script type= "text/javascript ">
function showsub(sid)
{
whichEl = eval( "alsub " + sid);
if (whichEl.style.display == "none ")
{
eval( "alsub " + sid + ".style.display=\ "\ "; ");
}