这儿哪里错了.图片不显示?半天也解决不了
在DatagriD中,第一列是模板列imagebutton =pic.
我在CS中
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
e.Item.Attributes.Add( "onclick ", "test() ");
在ASPX中:
function test()
{
var tr = window.event.srcElement;
tr.style.backgroundColor= "Red ";
var inputs = tr.getElementsByTagName( "INPUT ");
for(var i=0;i <inputs.length;i++)
{
if(inputs[i].type= "image ")
{
if(inputs[i].style.display= " " || inputs[i].style.display== "none ")
inputs[i].style.display= "block ";
else
inputs[i].style.display= "none ";
}
}
}
但当点击一行时,模板列不能显示
我想达到效果是:当点击x行时,这一行的模板列控件就显示,再点这一行时,又隐藏
------解决方案--------------------if(inputs[i].type= "image ")
{
if (inputs[i].style.display== "block ")
{
inputs[i].style.display= "none ";
}else{
inputs[i].style.display= "block "
}
}
试试
------解决方案-------------------- <asp:DataGrid id= "DataGrid1 " runat= "server ">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Image style= "float:right " ID= "Image1 " Runat= "server " ImageUrl= "1.bmp " />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
//可以运行,但是不是点图片,而是点单元格的空隙
function test()
{
var tr = window.event.srcElement;
tr.style.backgroundColor= "Red ";
var img = tr.getElementsByTagName( "img ");
for(var i = 0; i < img.length; i++)
{
if(img[i].style.display == " " || img[i].style.display == "none ")
img[i].style.display = "block ";
else
img[i].style.display = "none ";
}
}