如何在Javascript中找到GridView中的Image控件

时间:2014-08-22 09:57:39

标签: javascript asp.net gridview

如何在JavaScript中查找图像控件源。图像控件位于GridView的ItemTemplate中。

请告诉我如何找到图像控制及其图像siurce ..

  <asp:GridView ID="gridViewTaxReturnDocuments" runat="server" OnRowCommand="gridViewTaxReturnDocuments_RowCommand"
    OnRowDataBound="gridViewTaxReturnDocuments_RowDataBound" AutoGenerateColumns="False">
       <Columns>

     <asp:TemplateField HeaderText="Show To Client">
       <ControlStyle Font-Size="Larger" />
       <ItemTemplate>
           <asp:ImageButton ID="imgOnOff" runat="server" ImageUrl='<%#isOnOff(Convert.ToBoolean(Eval("ShowToClient")))%>'
            OnClientClick='<%# "javascript:OnOffDocs(\""+ DataBinder.Eval(Container.DataItem,"RowID") +"\");return false;" %>'
            Height="16px" Width="28px" />
        </ItemTemplate>
     <ItemStyle HorizontalAlign="Center" />
     </asp:TemplateField>

      </Columns>
   </asp:GridView>

          function OnOffDocs(DocID) 
              {    
                     PageMethods.DocOnOff(DocID);
                    var gridViewTaxReturnDocuments = document.getElementById("gridViewTaxReturnDocuments").value;

                    var imgOnOff = gridViewTaxReturnDocuments.getElementById('imgOnOff');


                    if (imgOnOff.src.indexOf("switch-off.png") != -1) {
                        imgOnOff.src = "~/images/switch-on.png";
                    }
                    else if (imgOnOff.src.indexOf("switch-on.png") != -1) {
                        imgOnOff.src = "~/images/switch-off.png";
                    }
                }

1 个答案:

答案 0 :(得分:0)

使用JS查看页面上的所有图像标记&amp;检查id是否包含&#34; imgOnOff&#34;因此,您可以识别网格图像。

你准备对图像做些什么?