1

グリッドビュー内にパネルがあります。グリッド ビューでラジオ ボタンをクリックすると、ラジオ ボタンの jqueryclickイベントが呼び出されます。その部分は正常に機能しています...今、グリッドビュー内にあるパネルを参照する必要がありますが、それがラジオボタンリストを参照$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ます。また、ラジオボタンリストの兄弟ではありません..少なくともそうではないと思います...

4

2 に答える 2

3

.parentsを使用して、要素の親を検索します。cssクラスを指定すると、次のことができます。

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

それを見つけるために。パネルはradiobuttonlistの親であると思います。それ以外の場合は、別のJqueryメソッドを使用する必要があります。これは、パネルが表示されているか、以下を使用して非表示になっている限り機能します。

<asp:Panel .. style="display:none" />
于 2012-08-23T16:17:43.613 に答える
1

パネルに css クラスを与えてから、jQuery セレクターを使用することをお勧めします。ラジオ ボタンがパネルの兄弟である場合:

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

生成されたマークアップのどこにパネルが配置されるかによって異なります。おそらく、代わりに next または prev を使用できます。生成されたマークアップを投稿していただければ、この回答を更新できます。


これで、次のように親と兄弟が必要なマークアップが表示されます (ありがとうございます)。

 <someOtherElement> <!-- the grid view container -->
    <div class="answer"></div> <!-- sibling of parent (maybe <div runat="server"> is better than panel?)  -->
    <div> <!-- parent -->
        <input type="radio">  <!-- this -->
    </div>
 </someOtherElement>
于 2012-08-23T16:19:13.197 に答える