2014-03-04 38 views
0

我使用javascript來設置hidden字段的值,我將這些值從javascript function中傳遞過來。下面是從aspx在ASP.Net中將動態參數傳遞給javascript

<table> 
    <% if (dtLevel1.Rows.Count > 0) 
     { 
      foreach (System.Data.DataRow dr in dtLevel1.Rows) 
       { 
        %><tr> 
         <td width="11%"> 
          <img class="imgClass" alt="" src="/Styles/expand-large-silver-Shapes4FREE.png" height="11px" 
           onclick="meClick(this)" /> 
          &nbsp; 
         </td> 
         <td> 
          <% if (dr["HaveChildren"].ToString() == "True") 
             { 
              string id = dr["LinkID"].ToString(); 
          %> 
          <a onclick="showPopUp('l1',''dynamic value)"><span style="font-size: 18px"> 
           <%= dr["LinkName"]%></span></a> 
          <%} 
             else 
             { %> 
          <span style="font-size: 18px"> 
           <%= dr["LinkName"]%></span> 
          <%} %> 
         </td> 
        </tr> 
        <% 
       } 
      } 
    %> 
</table> 

一些代碼,請看看這兩條線:

  1. string id = dr["LinkID"].ToString(); ID從DataTable到來。我想從這個下面的代碼通過這個值作爲第二個參數: <a onclick="showPopUp('l1',''dynamic value)">

我們怎樣才能做到這一點?

我已經嘗試過

<a onclick="showPopUp('l1','+"'"+id+"'"+')"><a onclick="showPopUp('l1',\'' + id + '\')"> 但沒有奏效。

回答

0

請嘗試以下操作。

<a onclick="showPopUp('l1','<%= dr["LinkID"].ToString() %>')"> 
+0

You Rock bhai :) – SMI