2016-08-30 18 views
0

私のアプリケーションでは、jQuery関数があり、この関数をgridviewリンクボタンから呼び出す必要があります。私はここに示されているこのコードを試してみましたが、関数が呼び出されません。GridviewリンクボタンからjQuery関数を呼び出す

<script type="text/javascript">  
    $(function() { 
     var JavascriptBlah = '<%=msUntilFour%>' 
     var fileName = '<%=msUntilFour%>';   
     $('input[id$="lnkCustomer"]').click(function() { 
      $("#dialog").dialog({ 
       modal: true, 
       title: fileName, 
       width: 600, 
       height: 600, 
       buttons: { 
        Close: function() { 
         $(this).dialog('close'); 
        } 
       }, 
       open: function() { 
        var object = "<object data=\"{FileName}\" type=\"application/pdf\" width=\"700px\" height=\"700px\">"; 
        object += "If you are unable to view file, you can download from <a href = \"{FileName}\">here</a>"; 
        object += "</object>"; 
        object = object.replace(/{FileName}/g, "Doc/Demo.pdf"); 
        $("#dialog").html(object); 
       } 
      }); 
     }); 
    }); 
</script> 

ASPXマークアップ:

<asp:GridView ID="gridView1" runat="server" CssClass="mydatagrid" 
     HeaderStyle-CssClass="header" RowStyle-CssClass="rows" 
     AutoGenerateColumns="false" 
     PageSize="10" EmptyDataText="No Records Available"> 
     <HeaderStyle CssClass="header"></HeaderStyle> 
     <PagerStyle ForeColor="Red" HorizontalAlign="Center"></PagerStyle> 
     <Columns> 
      <asp:BoundField DataField="Id" HeaderText="Id" /> 
      <asp:BoundField DataField="Name" HeaderText="Name" /> 
      <asp:TemplateField HeaderText="CustomerID"> 
       <ItemTemplate> 
        <asp:LinkButton runat="server" ID="lnkCustomer" Text='<%#Eval("Name") %>'> 
        </asp:LinkButton> 
       </ItemTemplate> 
      </asp:TemplateField> 
     </Columns> 
     <RowStyle CssClass="rows"></RowStyle> 
    </asp:GridView> 
</div>  
<div id="dialog" style="display: none"> 

がどのように私はGridViewのリンクボタンからjQueryの関数を呼び出すことができますか?

ありがとうございます。

+1

この[リンク](http://stackoverflow.com/questions/13782051/calling-jquery-function-from- gridview-link)が役に立ちます。 –

+0

Thnq @ devansh-nigam。それは働いている –

+0

あなたがそれが有用だと思うなら、私のコメントをupvoteしてください。ありがとう。 –

答えて

0

関数は、行ごとに複数のIDを生成するので、idで関数を呼び出さないでください。 これを実現するにはjavascriptを使用するだけでクライアント側のイベントをonclick = 'myTestFun(); LinkBut​​tonに

0

まず、スクリプトセクションで関数を宣言してからOnClientClickプロパティをLinkButtonに追加します。

ASPXコード

<asp:LinkButton runat="server" ID="lnkCustomer" Text='<%#Eval("Name") %>' 
OnClientClick="OpenModel();" > </asp:LinkButton> 

JSコード

$(document).ready(function(){ 
    OpenModel(); 
}); 
function OpenModel() { 
     $("#dialog").dialog({ 
      modal: true, 
      title: fileName, 
      width: 600, 
      height: 600, 
      buttons: { 
       Close: function() { 
        $(this).dialog('close'); 
       } 
      }, 
      open: function() { 
       var object = "<object data=\"{FileName}\" type=\"application/pdf\" width=\"700px\" height=\"700px\">"; 
       object += "If you are unable to view file, you can download from <a href = \"{FileName}\">here</a>"; 
       object += "</object>"; 
       object = object.replace(/{FileName}/g, "Doc/Demo.pdf"); 
       $("#dialog").html(object); 
      } 
     }); 
    }); 
関連する問題