2015-02-04 24 views
2

所以我有这些行旋转图像,如何在一个CommandField

command field rows

每行有我的.aspx页面中一个命令字段。

<asp:CommandField ControlStyle-BackColor="White" ItemStyle-BackColor="White"  SelectImageUrl="~/Styles/img/arrow_state_blue_right.png" 
              ShowSelectButton="true" ButtonType="Image" ItemStyle-Width="3px"></asp:CommandField> 

正如您所看到的,命令字段使用的按钮类型是图像。图像是您在图片中每个命令字段中看到的蓝色小箭头。

我希望箭头在用户点击命令字段时通过动画进行旋转。 所以我写了一个小javascript函数:当箭头的图像场

function rotateArrow() { 
    document.getElementById("#arrow").style.WebkitTransitionDuration = "1s"; 
    document.getElementById("#arrow").style.webkitTransform = 'rotate(40deg)'; 
} 

此功能就好了。即,如果我改变的箭头一样的东西:

<asp:Image ImageURL="..... 

但我不想箭头是asp.NET图像领域,我希望他们在我的命令字段的按钮。

有没有办法做到这一点?我如何告诉JavaScript来旋转我的命令字段的箭头图像属性?我无法找到任何关于此的内容,所以我开始认为这根本不被支持。我能想到的唯一解决办法并不意味着我失去了命令字段功能,我可以简单地更新后面代码中的selectImageURL属性,但后来我没有动画。

+1

我的建议...检查命令字段中的元素...看起来像呈现为输入...然后使用jQuery将单击事件附加到此元素,单击事件时会旋转它。会带给你更多的信息,但我知道它可以做到。我只是没有时间去做研究并为你写代码。你能行的! –

回答

0

如果有人正在努力访问命令字段或类似内容中的属性,这里有一个解决方案。 隐藏字段中的图像是ImageButton。 这是我的GridView在我的.aspx文件CommandField中:

<asp:GridView ID="gvColumnsViewSettings" runat="server" Width="90%" OnRowDataBound="gvColumnsViewSettings_RowDataBound" AutoGenerateColumns="false" GridLines="None" ShowHeader="false" ShowFooter="false" OnSelectedIndexChanged="gvColumnsViewSettings_SelectedIndexChanged" DataKeyNames="ColumnOrder"> 
    <Columns> 
    <asp:CommandField ControlStyle-BackColor="White" ItemStyle-BackColor="White" SelectImageUrl="~/Styles/img/arrow_state_blue_right.png" ShowSelectButton="true" ButtonType="Image" ItemStyle-Width="3px"></asp:CommandField> 
... 

注意如何在gridview的指数发生变化时,它调用的函数gvColumnsViewSettings_SelectedIndexChanged。

现在的SelectedIndexChanged函数中仅次于我的代码:

ImageButton arrow = null; 
if(selectedRow.Cells != null && selectedRow.Cells.Count > 0 && selectedRow.Cells[0].Controls != null && selectedRow.Cells[0].Controls.Count > 0) 
    arrow = (ImageButton)selectedRow.Cells[0].Controls[0]; 

现在,你有你的CommandField中内的箭头图像属性!