Container.ItemIndex应用
//隔行变色:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr id='tr_<%#Container.ItemIndex %>' style="background-color: #FAFBFF;" onmouseenter="javascript:this.style.backgroundColor='#FFF7D3';"
onmouseleave="javascript:this.style.backgroundColor='#FAFBFF';">
.......
........
//获取行号:
<form id="form_<%#Container.ItemIndex %>" method="post" action="TEST.aspx<%#Request.Url.Query %>">
</form>
贴出源码:
common.js
function getAbsolutePoint(id)
{
var temp=document.getElementById(id);
var curleft = curtop = 0;
if (temp.offsetParent)
{
curleft = temp.offsetLeft;
curtop = temp.offsetTop;
while (temp = temp.offsetParent)
{
curleft += temp.offsetLeft;
curtop += temp.offsetTop;
}
}
return {left:curleft,top:curtop};
}
//绑定鼠标移动事件已获得当前鼠标位置
var mousePoint={left:0,top:0};
//event对象
function MouseMove(e){
if(!document.all)
{
mousePoint={left:e.pageX,top:e.pageY};
}
else
{
mousePoint={left:(event.clientX+document.body.scrollLeft - document.body.clientLeft),top:(event.clientY + document.body.scrollTop - document.body.clientTop)};
}
}
=================
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TEST.aspx.cs" Inherits="ytoin_Route_debug_TEST" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script src="css/common.js" type="text/javascript"></script>
</head>
<body>
<div>
<table width="98%" border="0" cellpadding="0" cellspacing="1" bgcolor="#999999" align="center">
<tr style="font-size: 13px; color: White; font-weight: bold;">
<td>
ID</td>
<td>
网点代码</td>
<td>
公司名</td>
<td>
省份</td>
<td>
操作</td>
</tr>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr id='tr_<%#Container.ItemIndex %>' style="background-color: #FAFBFF;" onmouseenter="javascript:this.style.backgroundColor='#FFF7D3';"
onmouseleave="javascript:this.style.backgroundColor='#FAFBFF';">
<td>
null
</td>
<td>
<div>网点代码:<%#Eval("网点代码4")%></div>
</td>
<td>
<div>公司名:<%#Eval("始发网点3")%></div>
</td>
<td>
<div>省份:<%#Eval("所属省1")%></div>
</td>
<td>
<form id="form_<%#Container.ItemIndex %>" method="post" action="TEST.aspx<%#Request.Url.Query %>">
<select id="types" name="types">
<option value="0">启用</option>
<option value="1">暂停</option>
</select>
<input type="button" value="操作" onclick="javascript:show(document.getElementById('form_<%#Container.ItemIndex %>'),'<%#Eval("网点代码4") %>','<%#Eval("始发网点3") %>','<%#Eval("所属省1") %>',document.getElementById('tr_<%#Container.ItemIndex %>'));" />
<input type="hidden" id="txLogisticID" name="txLogisticID" value="<%#Eval("网点代码4")%>"
style="width: 1px;" />
<input type="hidden" id="reason" name="reason" style="width: 1px;" />
</form>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
</div>
<table id="messagebox" cellpadding="0" cellspacing="0" border="solid 1px black" style="background-color: White;
position: absolute; left: 330px; top: 150px; display: none;">
<tr>
<td>
网点代码:</td>
<td id="DM">
fff
</td>
<td>
</td>
</tr>
<tr>
<td>
公司:</td>
<td id="GS">
fff
</td>
<td>
</td>
</tr>
<tr>
<td>
省份:</td>
<td id="SF">
fff
</td>
</tr>
<tr id="reason_tr">
<td>
暂停原因:</td>
<td>
<textarea id="txtreason" style="width: 235px; height: 104px"></textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input id="ok" type="button" value="确定" />
<input id="cancel" type="button" value="取消" />
</td>
</tr>
</table>
<script type="text/javascript">
function show(form,DM,GS,SF,tr)
{
if(form.types.value=='0')
{
form.submit();
return;
}
setLocation();
messagebox.style.display="block";
document.getElementById("SF").innerHTML=SF;
document.getElementById("GS").innerHTML=GS;
document.getElementById("DM").innerHTML=DM;
document.getElementById("ok").onclick=function(){
form.reason.value=document.getElementById("txtreason").value;
messagebox.style.display="none";
form.submit();
};
document.getElementById("cancel").onclick=function(){
messagebox.style.display="none";
};
function setLocation()
{
var point=getAbsolutePoint(tr.id);
messagebox.style.top=(point.top+25)+"px";
}
}
</script>
</body>
</html>