2016-05-15 6 views
0

私はImageButtonを持っているGridviewを持っています。これは、hfComplete(隠しフィールド)の値に基づいてイメージを表示します。Gridview ImageButtonはマウスオーバーとマウスアウトで画像を変更します

値がtrueの場合、「images/completeiconfixed.png」と表示され、onmouseoverに属性を添付します。「this.src = 'images/completeiconfixed_transparant.png';」

falseの場合、「images/completeiconfixed_transparant.png」と表示され、その属性をonmouseoutに追加します。「this.src = 'images/completeiconfixed.png';」

これまでのところ、これまでのところ初めて初めて正常に動作しています。それは画像をうまく読み込みます。最初にマウスを置くと、画像は変わりますが、2回目は変わりません。

どのようにすべてのマウスの上と外で動作させるか考えています。私のコードは荒いです。

<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

関連する問題