2016-05-15 185 views
0

我有我有一個Imagebutton的GridView。它顯示基於hfComplete(hiddenfield)值的圖像。Gridview ImageButton改變鼠標懸停和鼠標移動的圖像

如果該值爲true,則顯示「images/completeiconfixed.png」並將該屬性附加到onmouseover「this.src ='images/completeiconfixed_transparant.png';」

如果爲false,則顯示「images/completeiconfixed_transparant.png」,並將該屬性附加到onmouseout「this.src ='images/completeiconfixed.png';」

到目前爲止,它只是第一次正常工作。它加載的圖像很好,當我第一次鼠標移動它改變圖像,但第二次它沒有。

任何想法如何使它在每個鼠標上工作。我的代碼是波紋管。

<asp:TemplateField HeaderText="C"> 
    <ItemTemplate> 
     <asp:ImageButton ID="imgComplete" runat="server" CommandName="completeRecord" 
      CommandArgument='<%# Eval("TaskID") + "," + Eval("Completed")%>' 
      Height="16px" Width="16px"/> 
    </ItemTemplate> 
    <ItemStyle CssClass="mycol-md-3px mycol-xs-3px"></ItemStyle> 
</asp:TemplateField> 


protected void grdNetwork_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
    if (e.Row.RowType == DataControlRowType.DataRow) 
    { 
     ImageButton imgComplete = (ImageButton)e.Row.FindControl("imgComplete"); 
     if (Convert.ToBoolean(hfCompleted.Value) == true) 
     { 
      imgComplete.ImageUrl = "images/completeiconfixed.png"; 
      imgComplete.Attributes.Add("onmouseover", "this.src='images/completeiconfixed_transparant.png';"); 
     } 
     else 
     { 
      imgComplete.ImageUrl = "images/completeiconfixed_transparant.png"; 
      imgComplete.Attributes.Add("onmouseout", "this.src='images/completeiconfixed.png';"); 
     } 
    } 
} 

在此先感謝。

回答

0

您可以通過設置在這兩種情況下onmouseoveronmouseout得到你想要的行爲:

protected void grdNetwork_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
    if (e.Row.RowType == DataControlRowType.DataRow) 
    { 
     ImageButton imgComplete = (ImageButton)e.Row.FindControl("imgComplete"); 
     if (Convert.ToBoolean(hfCompleted.Value)) 
     { 
      imgComplete.ImageUrl = "images/completeiconfixed.png"; 
      imgComplete.Attributes.Add("onmouseover", "this.src='images/completeiconfixed_transparant.png';"); 
      imgComplete.Attributes.Add("onmouseout", "this.src='images/completeiconfixed.png';"); 
     } 
     else 
     { 
      imgComplete.ImageUrl = "images/completeiconfixed_transparant.png"; 
      imgComplete.Attributes.Add("onmouseover", "this.src='images/completeiconfixed.png';"); 
      imgComplete.Attributes.Add("onmouseout", "this.src='images/completeiconfixed_transparant.png';"); 
     } 
    } 
} 
+0

太好了!有用。非常感謝 :) – Raja