我有一个网格视图grdtest
。我想使用 JQuery 从出现在锚点单击的模式对话框中更新网格中的文本框。我已经添加了代码,但模式对话框更新了网格中的所有文本框。如何仅更新与锚点位于同一行的文本框?
html代码是
<div id="output">
<asp:GridView ID="grdtest" CssClass="grid" Width="20%" AutoGenerateColumns="false" runat="server"
DataKeyNames="ID" OnRowCreated="grdtest_RowCreated" OnRowCommand="grdtest_RowCommand">
<Columns>
<asp:BoundField DataField="ID" Visible="false" />
<asp:BoundField HeaderText="NAME" DataField="NAME" ItemStyle-Width="5%"/>
<asp:TemplateField HeaderText="MONTH" ItemStyle-Width="5%">
<ItemTemplate>
<asp:TextBox ID="txtsubject" runat="server" Wrap="true"></asp:TextBox>
</ItemTemplate></asp:TemplateField>
<asp:TemplateField ItemStyle-Width="2%">
<ItemTemplate><a href="#" >Month</a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<div id="overlay" class="web_dialog_overlay"></div>
<div id="dialog" class="web_dialog">
<table style="width: 100%; border: 0px;" cellpadding="3" cellspacing="0">
<tr>
<td class="web_dialog_title">Month Chooser</td>
<td class="web_dialog_title align_right">
<a href="#" id="btnClose">Close</a>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2" style="padding-left: 15px;">
<b>Choose the months from the list </b>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2" style="padding-left: 15px;">
<div id="months">
<input id="month1" name="month" type="checkbox" value="Jan" />January
<input id="month2" name="month" type="checkbox" value="Feb" />February
<input id="month3" name="month" type="checkbox" value="Mar" />March
<input id="month4" name="month" type="checkbox" value="Apr" />April
<input id="month5" name="month" type="checkbox" value="May" />May
</div>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2" style="text-align: center;">
<input id="btnSubmit" type="button" value="Submit" />
</td>
</tr>
</table>
</div>
</form>
</body>
js代码是
<script type="text/javascript">
$(document).ready(function ()
{
$("#btnClose").click(function (e)
{
HideDialog();
e.preventDefault();
});
$('#btnSubmit').click(function(e)
{
var sub = [];
$(':checkbox:checked').each(function(i){
sub[i] = $(this).val();
});
$("#grdtest").find("input[type=text][id*=txtsubject]").val(sub);
HideDialog();
e.preventDefault();
});
});
function ShowDialog(modal)
{
$("#overlay").show();
$("#dialog").fadeIn(300);
if (modal)
{
$("#overlay").unbind("click");
}
else
{
$("#overlay").click(function (e)
{
HideDialog();
});
}
}
function HideDialog()
{
$("#overlay").hide();
$("#dialog").fadeOut(300);
}
</script>