asp.net网格视图中的面板-我如何在jquery中找到它

Panel inside asp.net gridview - how can I find it in jquery?

本文关键字:jquery 网格 net 视图 asp      更新时间:2023-09-26

我在网格视图中有一个面板。当我单击网格视图中的单选按钮时,我调用jquery click事件的单选按钮。那部分工作正常。。。现在我需要引用网格视图中的面板,但我不能使用$this,因为它引用了我的单选按钮列表(我认为它引用了)。

我怎样才能得到这个小组的参考资料。

            $("#MainContent_gvLineItems input[id*='rbAnswer']").click(function () {
                var p = $(this).find('[id$=MainContent_gvLineItems_pnlAnswer]'); // find the panel but this wont work so what can I do here?
            });

我不知道我的语法是否适合id$=MainContent_gvLineItems_pnlAnswer,因为网格视图中的每一行的面板id都会更改。。。

编辑

以下是一些网格视图:

<asp:TemplateField HeaderText="Answer">
                            <ItemTemplate>
                               <div id="dMainAnswer">
                                <asp:RadioButtonList ToolTip="Please provide an answer to the method." RepeatDirection="Horizontal" ID="rbAnswer" runat="server" SelectedValue='<%# DataBinder.Eval(Container, "DataItem.AnswerID")%>'>
                                    <asp:ListItem Text="Yes" Value="Yes" style="color:green;"></asp:ListItem>
                                    <asp:ListItem Text="No" Value="No" style="color:red;"></asp:ListItem>
                                    <asp:ListItem Text="N/A" Value="N/A" style="color:gray;"></asp:ListItem>
                                    <asp:ListItem Value="" Text="" style="display: none" />
                                </asp:RadioButtonList>
                                   <asp:Panel ID="pnlAnswer" runat="server" Visible="False">
                                       <div id="dMainAnswerResponsibleType">
                                            <asp:RadioButtonList ID="rbRespType" ToolTip="Select responsible contact type." runat="server" RepeatDirection="Horizontal" AutoPostBack="true" SelectedValue='<%# DataBinder.Eval(Container, "DataItem.ResponsiblePartyType")%>' OnSelectedIndexChanged="rbRespType_SelectedIndexChanged">
                                                <asp:ListItem Selected="True" Text="TKSE" Value="TKSE">TKSE</asp:ListItem>
                                                <asp:ListItem Text="Other" Value="Other">Other</asp:ListItem>
                                                <asp:ListItem Value="" Text="" style="display: none" />
                                            </asp:RadioButtonList>
                                        </div>
                                        <div id="dMainAnswerResponsible"><a href="#" onclick="return false;" class="info">Res:<span>Select who is responsible in resolving this issue.</span></a>
                                             <asp:DropDownList ID="ddlEmployees" runat="server" 
                                                DataSource="<%# GetEmployees() %>" SelectedValue='<%# Eval("TKSEContact") %>' DataTextField="FullName" Width="75px"
                                                DataValueField="FullName" 
                                                ToolTip="Select the TKSE responsible party.">
                                            </asp:DropDownList>
                                            <asp:TextBox ID="txtContact" Text='<%# Eval("ResponsiblePartyContact") %>' Width="75px" MaxLength="50" runat="server" ToolTip="Enter the responsible contact name." Visible="false"></asp:TextBox>
                                        </div>
                                        <div id="dDueDate"><a href="#" onclick="return false;" class="info">Due:<span>Select the due date when you expect this issue to be resolved.</span></a>
                                            <asp:TextBox ID="txtDueDate" Text='<%# Eval("DueDate") %>' Width="59px" runat="server" ToolTip="Select the due date." CssClass="datePickerDueDate"></asp:TextBox>
                                        </div>
                                        <div id="cSendToSugar">
                                            <asp:CheckBox ID="chkSendToSugar" ToolTip="Send/Update issue to Sugar?" BackColor="Gold" Text="Send To Sugar?" Checked="true" runat="server" />
                                        </div>
                                   </asp:Panel>
                               </div>
                            </ItemTemplate>
                                <FooterStyle HorizontalAlign="Center" />
                                <HeaderStyle HorizontalAlign="Center" />
                                <ItemStyle HorizontalAlign="Center" />
                            </asp:TemplateField>

请注意面板pnlAnswer,它最初设置为不可见的Visible=False。它也不是单选按钮列表的兄弟项。。至少我不认为是…

使用.eparents查找元素的父元素;如果你给它一个css类,你可以做:

$(this).parents(".class:first")

找到它。我想这个面板是单选按钮列表的父面板。否则,您将希望使用另一个Jquery方法。只要面板是可见的,或者使用隐藏,这就可以工作

<asp:Panel .. style="display:none" />

我建议给你的面板一个css类,然后使用jQuery选择器。如果单选按钮是面板的同级按钮:

var panel = $(this).siblings(".answer");

这取决于面板在生成的标记中的位置,也许可以使用next或prev。如果你发布生成的标记,我可以更新这个答案。


现在,我们可以看到标记(谢谢),你需要父母,然后是兄弟姐妹,就像这样:

 <someOtherElement> <!-- the grid view container -->
    <div class="answerswer"></div> <!-- sibling of parent (maybe <div runat="server"> is better than panel?)  -->
    <div> <!-- parent -->
        <input type="radio">  <!-- this -->
    </div>
 </someOtherElement>