2011-08-30 40 views
1

我想讀取JQuery中的項目值,根據我希望啓用或禁用基於標籤值的列表視圖中的錨定標記的值。任何幫助,將不勝感激。如何閱讀JQuery中的列表視圖項目(標籤)

$(document).ready(function() { 
     $('#Coverage-link').live('click', function(e) { 
        var IsRestriction = ***I want to read a label text(lblRestrictions) here*** 
        if (IsRestriction == "More") { 
         $('#Coverage-form').dialog('open'); 
        } else { 
         e.preventDefault(); 
        } 
        return false; 
       }); 
}); 

ListView項 -

<ItemTemplate> 
       <tr > 
        <td align="left" style="width:180px"> 
         <asp:Label ID="lblDrugName" runat="server" Text='<%# Eval("DrugDescription") %>' /> 
        </td> 
        <td style="width:120px" align="center"> 
         <asp:Label ID="lblStatus" runat="server" Text='<%# Eval("FormularyStatusDescription") %>' /> 
        </td> 
        <td align="left" style="width:250px"> 
         <asp:Label ID="lblFlat" runat="server" Text='<%# Eval("CopayInfo") %>' /> 
        </td>  
        <td style="width:80px;padding-right:10px;" align="center"> 
         <!--<asp:Label ID="lblCoverageRestrictions" runat="server" Text='<%# Eval("Restrictions") %>' /> --> 
         <a href="#" id="Coverage-link"> 
         <asp:Label ID="lblRestrictions" runat="server" Text='<%# Eval("Restrictions") %>' ></asp:Label> 
         </a> 
        </td> 
       </tr> 
      </ItemTemplate>  

下面是HTML輸出 -

<table id="eligibility-data"> 
        <thead style="background-color:#90a595;"> 
         <th style="width:180px">Drug Name</th> 
         <th style="width:120px;">Formulary Status</th> 
         <th align="left" style="width:250px">Copay Information</th> 
         <th style="width:80px;padding-right:10px">Restrictions</th> 
        </thead> 
        <tbody> 

       <tr > 
        <td align="left" style="width:180px"> 
         <span id="ctl00_MainContentPlaceholder_formularyControl_lvCopayInformation_ctrl0_lblDrugName">ibuprofen 200 mg oral capsule</span> 
        </td> 
        <td style="width:120px" align="center"> 
         <span id="ctl00_MainContentPlaceholder_formularyControl_lvCopayInformation_ctrl0_lblStatus">On - Preferred (2)</span> 
        </td> 
        <td align="left" style="width:250px"> 
         <span id="ctl00_MainContentPlaceholder_formularyControl_lvCopayInformation_ctrl0_lblFlat">No Copay Info Available.</span> 
        </td>  
        <td id="tdRestrictions" style="width:80px;padding-right:10px;" align="center"> 
         <!--<span id="ctl00_MainContentPlaceholder_formularyControl_lvCopayInformation_ctrl0_lblCoverageRestrictions">None</span> --> 
         <a href="#" id="Coverage-link"> 
         <span id="ctl00_MainContentPlaceholder_formularyControl_lvCopayInformation_ctrl0_lblRestrictions">None</span> 
         </a> 
        </td> 
       </tr> 

        </tbody> 
       </table> 
+0

您可以共享最終的HTML輸出,而不是ASP服務器端代碼嗎? – Blazemonger

+0

請找到添加的HTML代碼。 – Senthil

回答

0

我會假設指令輸出裏面的內容的HTML標籤。

然後,檢索您可以使用標籤文本:

var IsRestriction = $('#Coverage-link label').text() 

的IsRestriction變量應該再有ASP的字符串:標籤指令

+0

謝謝eltuza。 ASP:標籤有簡單的文字「無」或「更多」基於此我想打開一個使用JQuery的表單。我已經添加了列表視圖的HTML輸出,請參閱它。 – Senthil

0

何樂而不爲呢ItemDataBound在服務器端?

protected void ContactsListView_ItemDataBound(object sender, ListViewItemEventArgs e) 
{ 
    //Label EmailAddressLabel; 
    if (e.Item.ItemType == ListViewItemType.DataItem) 
    { 
     //PUT YOUR LOGIC HERE 

     // Display the e-mail address in italics. 
     //EmailAddressLabel = (Label)e.Item.FindControl("EmailAddressLabel"); 
     //EmailAddressLabel.Font.Italic = true; 

     //System.Data.DataRowView rowView = e.Item.DataItem as System.Data.DataRowView; 
     //string currentEmailAddress = rowView["EmailAddress"].ToString(); 
     //if (currentEmailAddress == "[email protected]") 
     //{ 
     //EmailAddressLabel.Font.Bold = true; 
     //} 
    } 
} 
+0

嗨瑞克。我發現自己和Senthil在同一條船上。通過上面的代碼,我可以看到他試圖在CSS樣式的DIV框中顯示數據,這是客戶端,因此可以通過jQuery訪問。我還沒有找到辦法做到這一點。 – jp2code