我有一个asp.net页面
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
<%--<div class="tab-content">--%>
<%-- <div id="home" class="tab-pane fade in active">--%>
<div class="container" id="div_frm">
<form id="frmQuestion">
<div class="panel panel-primary">
<div class="panel-body" style="max-height: 400;overflow-y: scroll;">
<asp:ScriptManager ID="scriptmgr" runat="server"> </asp:ScriptManager>
<asp:UpdatePanel ID="upd" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Repeater ID="rptQuestions" runat="server">
<HeaderTemplate>
<table class="table" cellpadding="5px" cellspacing="10px" border="solid" id="tableQuestion">
<tr style="color:Black; background-color:Teal; border:solid;">
<th style="width:20px">No.</th>
<th style="width:100px">Question</th>
<th style="width:40px">QuestionType</th>
<th style="width:110px">Text Answer</th>
<th style="width:100px">Multiple Choice 1</th>
<th style="width:100px">Multiple Choice 2</th>
<th style="width:100px">Multiple Choice 3</th>
<th style="width:100px">Multiple Choice 4</th>
<th style="width:70px">True/False</th>
<th>Controls</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="color:Black; background-color:Silver; border:solid;" id="trdata" class="trclass">
<td><asp:Label runat="server" ID="lblNo" Text='<%#Eval("Qno") %>' /></td>
<td><asp:Label runat="server" ID="lblQuestion" Text='<%#Eval("Question") %>'></asp:Label>
<asp:TextBox runat="server" ID="txtQuestion" Text='<%#Eval("Question") %>' Visible="false"></asp:TextBox>
<asp:Label runat="server" ID="lblQid" Text='<%#Eval("Qid") %>' Visible="false"></asp:Label></td>
<td><asp:Label runat="server" ID="lblQtype" Text='<%#Eval("Qtype") %>' ></asp:Label>
<asp:DropDownList runat="server" ID="ddlQType" Visible="false"></asp:DropDownList>
<%-- <select class="dropdown" id="ddlQType" name="ddlQType" style="width:100px" runat="server">
<option value="0">--Select--</option>
<option value="1">Descriptive Answer</option>
<option value="2">Multiple Choice </option>
<option value="3">True/False answer</option></select>--%></td>
<td><asp:Label runat="server" ID="lblAnsDesc" Text='<%#Eval("description") %>' Width="100px" ></asp:Label>
<asp:TextBox runat="server" ID="txtAnsDesc" Text='<%#Eval("description") %>' Width="100px" Visible="false"></asp:TextBox></td>
<td><asp:Label runat="server" ID="lblch1" Text='<%#Eval("choice1") %>' Width="100px" ></asp:Label>
<asp:TextBox runat="server" ID="txtch1" Text='<%#Eval("choice1") %>' Width="100px" Visible="false"></asp:TextBox></td>
<td><asp:Label runat="server" ID="lblch2" Text='<%#Eval("choice2") %>' Width="100px" ></asp:Label>
<asp:TextBox runat="server" ID="txtch2" Text='<%#Eval("choice2") %>' Width="100px" Visible="false"></asp:TextBox></td>
<td><asp:Label runat="server" ID="lblch3" Text='<%#Eval("choice3") %>' Width="100px" ></asp:Label>
<asp:TextBox runat="server" ID="txtch3" Text='<%#Eval("choice3") %>' Width="100px" Visible="false"></asp:TextBox></td>
<td><asp:Label runat="server" ID="lblch4" Text='<%#Eval("choice4") %>' Width="100px" ></asp:Label>
<asp:TextBox runat="server" ID="txtch4" Text='<%#Eval("choice4") %>' Width="100px" Visible="false"></asp:TextBox></td>
<td><asp:Label runat="server" ID="lblisTrue" Text='<%# Eval("isTrue") %>' Width="70px" ></asp:Label>
<asp:CheckBox runat="server" ID="chkistrue" Checked='<%#(Eval("isTrue")=="true") %>' Width="70px" Visible="false"/></td>
<td> <span class="more"><asp:LinkButton ID="lnkEdit" Text="Edit" runat="server" data-toggle="modal" data-target="#myModal" OnClientClick="getdata();" CausesValidation="false" />
<asp:LinkButton ID="lnkUpdate" Text="Update" runat="server" Visible="false" OnClick="OnUpdate" CausesValidation="false" />
<asp:LinkButton ID="lnkCancel" Text="Cancel" runat="server" Visible="false" OnClick="OnCancel" CausesValidation="false" />
<asp:LinkButton ID="lnkDelete" Text="Delete" runat="server" OnClick="OnDelete" CausesValidation="false" OnClientClick="return confirm('Do you want to delete this row?');" />
</span></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
<!-- Modal example -->
<!-- Trigger the modal with a button -->
<p class="text-center"><button type="button" class="btn btn-info" data-toggle="modal" data-target="#myModal" id="btnshowmodal" runat="server">Edit</button>    </p>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title text-center">RESULT</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-3">
<asp:Label runat="server" ID="lblQuestionNumber" />
</div>
<div class="col-md-8">
<asp:TextBox runat="server" ID="txtQuestionDesc" />
</div>
<div class="col-md-1"></div>
</div>
<div class="row">
<div class="col-md-3">
<asp:Label runat="server" ID="lblQuestionType" Text="Select Type :"></asp:Label>
</div>
<div class="col-md-8">
<select class="dropdown" id="ddlQType" name="ddlQType" onchange="ShowHide();return false;" style="width:310px" >
<option value="0">--Select--</option>
<option value="1">Descriptive Answer</option>
<option value="2">Multiple Choice </option>
<option value="3">True/False answer</option></select>
</div>
<div class="col-md-1"></div>
</div>
<div class="row">
<div class="col-md-3">
<asp:Label runat="server" ID="Label1" Text="Answer :"></asp:Label>
</div>
<div class="col-md-8">
<textarea runat="server" id="textareaQuestion" rows="2" cols="40"/>
</div>
<div class="col-md-1"></div>
</div>
<div class="row">
<div class="col-md-3">
<asp:Label runat="server" ID="Label2" Text="True/False :"></asp:Label>
</div>
<div class="col-md-8">
<asp:RadioButton runat="server" ID="rbtrue" Text=" True " GroupName="tf" />
<asp:RadioButton runat="server" ID="rbfalse" Text=" False " GroupName="tf" />
</div>
<div class="col-md-1"></div>
</div>
<div class="row">
<div class="col-md-3">
<asp:Label runat="server" ID="lblMultiAns1" Text="Enter first Choice :"></asp:Label>
</div>
<div class="col-md-8">
<asp:TextBox ID="txtMulti1" runat="server" Width="310px"></asp:TextBox>
<asp:CheckBox class="checkbox" runat="server" ID="chkmulti1" Text="Tick if answer is correct." />
</div>
<div class="col-md-1"></div>
</div>
<div class="row">
<div class="col-md-3">
<asp:Label runat="server" ID="lblMultiAns2" Text="Enter Second Choice :"></asp:Label>
</div>
<div class="col-md-8">
<asp:TextBox ID="txtMulti2" runat="server" Width="310px"></asp:TextBox>
<asp:CheckBox class="checkbox" runat="server" ID="chkmulti2" Text="Tick if answer is correct." />
</div>
<div class="col-md-1"></div>
</div>
<div class="row">
<div class="col-md-3">
<asp:Label runat="server" ID="lblMultiAns3" Text="Enter Third Choice :"></asp:Label>
</div>
<div class="col-md-8">
<asp:TextBox ID="txtMulti3" runat="server" Width="310px"></asp:TextBox>
<asp:CheckBox class="checkbox" runat="server" ID="chkmulti3" Text="Tick if answer is correct." />
</div>
<div class="col-md-1"></div>
</div>
<div class="row">
<div class="col-md-3">
<asp:Label runat="server" ID="lblMultiAns4" Text="Enter Fourth Choice :"></asp:Label>
</div>
<div class="col-md-8">
<asp:TextBox ID="txtMulti4" runat="server" Width="310px"></asp:TextBox>
<asp:CheckBox class="checkbox" runat="server" ID="chkmulti4" Text="Tick if answer is correct." />
</div>
<div class="col-md-1"></div>
</div>
<div class="row">
<div class="col-md-3">
</div>
<div class="col-md-8">
<asp:Button class="btn" runat="server" ID="Button1" Text="Save" OnClick="btnSave_Click" />
<asp:Button class="btn" runat="server" ID="Button2" Text="Cancel" CausesValidation="false"
onclick="btnCancel_Click" />
</div>
<div class="col-md-1"></div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</form>
</div>
当我点击转发器中的编辑链接按钮时,模式弹出窗口打开时显示空字段,但我想获取相应行的值 我尝试了行点击事件
$(function () {
$(".trclass").click(function () {
var quest = $(this).closest('[id*="lblQuestion"]').text();
alert(quest);
});
});
检查我是否可以访问这些值但是失败了。 那么我如何访问这些值并插入模态? 或者我需要改变设计吗?
答案 0 :(得分:0)
nearest()方法返回所选元素的第一个祖先。祖先是父母,祖父母,曾祖父母等等,所以它不起作用,你需要的是找到方法
var quest = $(this).find('[id*="lblQuestion"]').text();
find()方法返回所选元素的后代元素。