使用jQuery获取Gridview行中的Hyperlink值

时间:2012-10-23 16:29:31

标签: jquery asp.net gridview

我的gridview看起来像:

 <asp:GridView ID="gvFiles" runat="server" >
                                <Columns>
 <asp:TemplateField HeaderText="Notification Sent to">
                                        <ItemTemplate>
                                            <asp:Label ID="lblNotifSentTo" runat="server" CssClass="NotifSent"></asp:Label>
                                            <asp:HyperLink ID="hypNotifSentTo" runat="server"  CssClass="NotifSent2" NavigateUrl="#" 
                                                Text='<%# Eval("NotifSentToLabsStr") %>'></asp:HyperLink>
                                        </ItemTemplate>
                                    </asp:TemplateField>
  <asp:TemplateField>
                                        <ItemStyle Wrap="false" />
                                        <ItemTemplate>
                                            <div id="divIbtnEdit" runat="server" style="display: inline;">
                                                <asp:ImageButton ID="ibtnDelete" runat="server" ImageUrl="~/Images/Delete.gif"
                                                    ToolTip="Delete" />
                                                &nbsp;
                                            </div>
.......

当我点击删除按钮时,我需要在我做其他任何事情之前检查“通知发送到”超链接的值,但我似乎无法获得价值

这就是我现在所拥有的:

 $("input[id*='_ibtnDelete_']").live("click", function ($e) {

            var id = $(this).next('NotifSent2').val();
            var nm = $(this).find('input[id$=NotifSent2]').val();

            var nm = $(this).parent.find('input[id$=NotifSent2]').val();
            var x = $(this).find('[id$="NotifSent2"]').val();
            return confirm(x);



            if ($(this).attr('src') == "Images/Delete_gray.gif") {
                alert("This request cannot be deleted, because it is currently linked to other files. ");
                return false;
            }

            else {
                return confirm('Are you sure you want to delete this file?');
            }
        });

我一直在“未定义”

我在做错了什么?请帮忙。

这是生成的html:

<table cellspacing="0" cellpadding="8" id="ContentPlaceHolder1_gvFiles" style="background-color:White;border-color:#CCCCCC;border-width:1px;border-style:Solid;width:100%;border-collapse:collapse;">
                    <tr align="left" style="color:White;background-color:#ABAAC1;font-weight:bold;">
                        <th scope="col">&nbsp;</th><th scope="col">&nbsp;</th><th scope="col">&nbsp;</th><th scope="col">Type of Request</th><th scope="col">Status</th><th scope="col">Sender</th><th scope="col">Upload Date (EST)</th><th scope="col">Notification Sent to</th><th scope="col">&nbsp;</th><th scope="col">&nbsp;</th>
                    </tr><tr class="gvRowReqIncomplete">
                        <td>
                                            <td>HQ</td><td>10/23/2012 12:41:19 PM</td><td>
                                            <span id="ContentPlaceHolder1_gvFiles_lblNotifSentTo_0" class="uglyRed" style="display:inline;">No Recipient Selected!</span>
                                            <a id="ContentPlaceHolder1_gvFiles_hypNotifSentTo_0" class="NotifSent2" href="#" style="display:none;"></a>
                                        </td><td>

                                            <a id="ContentPlaceHolder1_gvFiles_hypResend_0" style="font-weight:bold;cursor:pointer;">Send Reminder</a>
                                        </td><td style="white-space:nowrap;">
                                            <div id="ContentPlaceHolder1_gvFiles_divIbtnEdit_0" style="display: inline;">
                                                <input type="image" name="ctl00$ContentPlaceHolder1$gvFiles$ctl02$ibtnEdit" id="ContentPlaceHolder1_gvFiles_ibtnEdit_0" title="Edit" src="Images/Edit.gif" />
                                                &nbsp;
                                            </div>
                                            <div id="ContentPlaceHolder1_gvFiles_divIbtnDelete_0" style="display: inline;">
                                                <input type="image" name="ctl00$ContentPlaceHolder1$gvFiles$ctl02$ibtnDelete" id="ContentPlaceHolder1_gvFiles_ibtnDelete_0" title="Delete" src="Images/Delete.gif" />
                                                &nbsp;
                                            </div>
                                            <div id="ContentPlaceHolder1_gvFiles_divIbtnUpdate_0" style="display: none;">
                                                <input type="image" name="ctl00$ContentPlaceHolder1$gvFiles$ctl02$ibtnUpdate" id="ContentPlaceHolder1_gvFiles_ibtnUpdate_0" title="Update" src="Images/Update.gif" />
                                                &nbsp;
                                            </div>
                                            <div id="ContentPlaceHolder1_gvFiles_divIbtnCancel_0" style="display: none;">
                                                <input type="image" name="ctl00$ContentPlaceHolder1$gvFiles$ctl02$ibtnCancel" id="ContentPlaceHolder1_gvFiles_ibtnCancel_0" title="Cancel" src="Images/Cancel.gif" />
                                            </div>
                                        </td>
                    </tr>
                </table>

3 个答案:

答案 0 :(得分:1)

NotifSent2是您必须使用的类。使用类选择器

更改

 var id = $(this).next('NotifSent2').val();

    var id = $(this).next('.NotifSent2').val();

答案 1 :(得分:1)

试试这个:

var id = $(".NotifSent2", $(this).closest("tr")).html();

答案 2 :(得分:0)

试试这个

$('table[id$=gvFiles] tr input[id$=ibtnDelete]').click(function(){
    var val=$(this).closest('tr').find('a[id$=hypNotifSentTo]').html();
    alert(val);
    });