table的数据是动态加载的,table是放在datalist中的
如何获取表格的最后一行?使其突出显示
<script language="javascript">
function TBtr(rowNum)
{
var tb=document.getElementById('tb2');
tb.rows[rowNum].style.color='green';
}
</script>后台
‘------------------------------------
绑定数据代码
Page.RegisterStartupScript("", "<script>TBtr('" & Adst.Tables("ProSrRe").Rows.Count - 1 & "');</script>")能得到rowNum的值
提示rows[].style不存在或不是对象。
如何获取表格的最后一行?使其突出显示
<script language="javascript">
function TBtr(rowNum)
{
var tb=document.getElementById('tb2');
tb.rows[rowNum].style.color='green';
}
</script>后台
‘------------------------------------
绑定数据代码
Page.RegisterStartupScript("", "<script>TBtr('" & Adst.Tables("ProSrRe").Rows.Count - 1 & "');</script>")能得到rowNum的值
提示rows[].style不存在或不是对象。
解决方案 »
- 请教CSDN的URL加密算法
- 关于VS2005模板列使用radiobutton,实现单选以及取出该行的数据 (在线)
- 三层间的方法的调用问题
- 提取页面链接的一个正则,汗,难倒偶了
- 求一条select语句(在线急等,解决立即结贴)
- 文件上传问题
- 关于textbox.text存进数据库的问题
- 求:一个VB.net写的类,有读、增、修、删的功能。在线等,急。
- repeater中模版中如何显示隐藏相关字段的显示!
- 请各位帮忙找一个用asp.net写的日历,急用
- 如何不在aspx页出现ADO.NET代码 , 来实现ASPNETPAGER分页
- 数字报纸是否有专业的系统?还是就是各自打造了CMS平台?每一家数字报纸的相似度很高啊
或者试用tb.lastChild 访问该元素试试
Page.RegisterStartupScript("", " <script>TBtr('" & Adst.Tables("ProSrRe").Rows.Count - 1 & "'); </script>")
把Page这句删掉
在body加
<body onload="TBtr(document.getElementById('tb2').rows.length-1)">
看一下rowNum是多少不就行了~
if(!Page.IsPostBack)
{
GridView1.DataSource = 数据源;
GridView1.DataBind();
}在页面里面
<script language="javascript">
function TBtr(rowNum)
{
var tb=document.getElementById('GridView1');
tb.rows[rowNum].style.color='green';
}
</script> <body onload="TBtr(document.getElementById('GridView1').rows.length-1)">
<ItemTemplate>
<table id="tb2" cellspacing="0">
<tr onmouseover="this.style.backgroundColor='#00ff00';this.style.color='#ff0000';this.style.cursor='hand'"
onmouseout="this.style.color='';this.style.backgroundColor=''">
<td width="8%" style="border-left:1px solid;border-bottom:1px solid;border-right:1px solid">
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.生管回復交期") %>' ID="Label1">
</asp:Label></td>
<td width="3%">
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.序號") %>' ID="Label51">
</asp:Label></td>
<td width="8%" style="border-bottom:1px solid;border-right:1px solid">
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.派工日期") %>' ID="Label2">
</asp:Label></td>
<td width="8%" style="border-bottom:1px solid;border-right:1px solid">
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.未交貨數量") %>' ID="Label3">
</asp:Label></td>
<td width="16%" style="border-bottom:1px solid;border-right:1px solid">
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.NCT生產進度") %>' ID="Label4">
</asp:Label></td>
<td width="8%" style="border-bottom:1px solid;border-right:1px solid">
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.預計NCT完成") %>' ID="Label9">
</asp:Label></td>
<td width="8%" style="border-bottom:1px solid;border-right:1px solid">
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.發烤漆日期") %>' ID="Label5">
</asp:Label></td>
<td width="8%" style="border-bottom:1px solid;border-right:1px solid">
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.回廠日期") %>' ID="label10">
</asp:Label></td>
<td width="8%" style="border-bottom:1px solid;border-right:1px solid">
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.[包材/線材]") %>' ID="Label6">
</asp:Label></td>
<td width="8%" style="border-bottom:1px solid;border-right:1px solid">
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.預計組裝日期") %>' ID="Label7">
</asp:Label></td>
<td width="10%" style="border-bottom:1px solid;border-right:1px solid">
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.預計組裝進度") %>' ID="Textbox3">
</asp:Label></td>
<td width="8%" style="border-bottom:1px solid;border-right:1px solid">
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.排程人") %>' ID="Label8">
</asp:Label></td>
</tr>
</table>
</ItemTemplate> ''接受參數制令單號
Dim ZLDH As String = Request.QueryString("ZLDH")
Astrsql = "select 序號,排程人,生管回復交期,派工日期,未交貨數量,NCT生產進度,預計NCT完成,發烤漆日期,回廠日期,[包材/線材],預計組裝日期,預計組裝進度 from T_ProPlanSched where 制令單號='" & ZLDH & "' order by 排程日期 asc"
Aadp = New SqlDataAdapter(Astrsql, Gcon)
Aadp.Fill(Adst, "ProSrRe")
dlProPlanSched.DataSource = Adst.Tables("ProSrRe")
dlProPlanSched.DataBind()
,把tr放里面就可以了
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
<tr><td><asp:Label ID="Label1" Text='<%# DataBinder.Eval(Container, "DataItem.預計組裝日期") %>' runat="server"/></td></tr>
</ItemTemplate>
</asp:DataList>
</table>
<HeaderTemplate> <table id="tb2" cellspacing="0">
</HeaderTemplate>
<ItemTemplate>
<TR onmouseover="this.style.backgroundColor='#00ff00';this.style.color='#ff0000';this.style.cursor='hand'"
onmouseout="this.style.color='';this.style.backgroundColor=''">
<td width="8%" style="border-left:1px solid;border-bottom:1px solid;border-right:1px solid">
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.生管回復交期") %>' ID="Label1">
</asp:Label></td>
<td width="8%" style="border-bottom:1px solid;border-right:1px solid">
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.派工日期") %>' ID="Label2">
</asp:Label></td> </TR>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:datalist>这样html显示有错误(要么缺少结束标记,要么与‘HeaderTemplate’重叠)
运行后alert(rowNum)能显示实际行数,但每次都是中间行的背景颜色变绿。
当有12行,第六行就变绿,为什么呢?
<!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>
<title>Error</title>
<script src="js/jquery-1.3.2.js" type="text/javascript"></script>
<script type="text/javascript" >
$(document).ready(function(){
$("tr:last").css("color","green");
});
</script>
</head>
<body>
<table></table></body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>test</title>
<script src="js/jquery-1.3.2.js" type="text/javascript"></script>
<script language="javascript">
$(document).ready(function(){
$("#tb2").find("tr:last").css("color","red");
});
</script>
</head>
<body>
<table id="tb2">
<tr><td>测试数据1</td></tr>
<tr><td>测试数据2</td></tr>
<tr><td>测试数据3</td></tr>
</table>
</body>
</html>
function changeColor()
{
var tbs = document.getElementsByTagName("table");
var count = 0;
for( i = 0;i < tbs.length;i++)
{
if(tbs[i].id == "tb2")
{
count++;
}
}
tbs[count].rows[0].style.backgroundColor = "blue";
}
have a try!@!
table套在外面 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!<table id="tb2" cellspacing="0">
<asp:datalist id="dlProPlanSched" runat="server" Width="100%">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<TR onmouseover="this.style.backgroundColor='#00ff00';this.style.color='#ff0000';this.style.cursor='hand'"
onmouseout="this.style.color='';this.style.backgroundColor=''">
<td width="8%" style="border-left:1px solid;border-bottom:1px solid;border-right:1px solid">
<asp:Label runat="server" Text=' <%# DataBinder.Eval(Container, "DataItem.生管回復交期") %>' ID="Label1">
</asp:Label> </td>
<td width="8%" style="border-bottom:1px solid;border-right:1px solid">
<asp:Label runat="server" Text=' <%# DataBinder.Eval(Container, "DataItem.派工日期") %>' ID="Label2">
</asp:Label> </td>
</TR>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:datalist>
</table>
asp:datalist id="dlProPlanSched" runat="server" Width="100%">
<HeaderTemplate> <table id="tb2" cellspacing="0">
</HeaderTemplate> <ItemTemplate>
<TR onmouseover="this.style.backgroundColor='#00ff00';this.style.color='#ff0000';this.style.cursor='hand'"
onmouseout="this.style.color='';this.style.backgroundColor=''">
<td width="8%" style="border-left:1px solid;border-bottom:1px solid;border-right:1px solid">
<asp:Label runat="server" Text=' <%# DataBinder.Eval(Container, "DataItem.生管回復交期") %>' ID="Label1">
</asp:Label> </td>
<td width="8%" style="border-bottom:1px solid;border-right:1px solid">
<asp:Label runat="server" Text=' <%# DataBinder.Eval(Container, "DataItem.派工日期") %>' ID="Label2">
</asp:Label> </td>
</TR>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:datalist> 但是我的办法经过tb.rows[rowNum*2+1].style.color='green'; 竟然能行了,不知道为什么啊?
用JQUERY的选择器吧,很方便的。 19楼的就是用的JQUERY。。 没有你那样麻烦的~~