2011-08-30 58 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