日期:2014-05-18  浏览次数:20629 次

怎么在js里面获取Repeater里面控件的Id
哪位高手能帮我解决在内容页中,怎么在repeater里面获取控件的Id!谢了

------解决方案--------------------
repeate 里面嵌套了table的话
就直接遍历table即可
var tb = document.getElementById("tbid");
for(var i=0;i<tb.rows.length;i++){
 alert(tb.rows[i].cells[0].firstChild.type)//找到某行第一列的第一个子控件
}
------解决方案--------------------
var table = document.getElementById("<%=Repeater1.ClientID %>");//这样找到你的reapter 控件的ID 记住是ClientID.

连起来应该这样写:
var lable1 = document.getElementById("<%=table .FindControl("Label1").ClientID%>");

意思你明白不 ?我解释一下吧
Repeater1.ClientID 控件在客户端的ID. 
table .FindControl("Label1").ClientID Lable的ID
------解决方案--------------------
用JS获取ID?

那可以先给repeater里那个控件取一个名字。。比如叫:aaa..

用JQUERY给你个示例,点击这个控件时,得到这个ID:
 
JScript code

       $("input[name='aaa']").click(function(){
            var a = $(this).attr("id");
            alert("这个控件的ID是:" + a);
       });

------解决方案--------------------
onclick="javascript:xianshi();">

=>

onclick="<%# GetClick(Container)%>">

C# code

protected string GetClick(Control ctrl)
{
   
   return string.Format("javascript:xianshi('{0}');",(ctrl.FindControl("yangrong")??new Control()).ClientID);
}

------解决方案--------------------
使用 

(sender as Control ).NamingContainer.FindControl("ConName") as TextBox