问题
i have gridview with following itemtemplate
<ItemTemplate>
<asp:TextBox ID="txtComments" runat="server" Text='<%# Bind("Comments") %>'
</asp:TextBox>
<asp:LinkButton href="#modal-dialog1" ID="href_Score" role="button" data-toggle="modal"
runat="server" class="icon-photon comment_alt2_stroke" OnClientClick='<%# string.Format("javascript:return GetScores(this,\"{0}\")", Eval("ExceptionID")) %>'>
</asp:LinkButton>
</ItemTemplate>
one text box is there inside gridview and one link button also to popup the text box data.I am able to pop up the data.
In pop up window i am having another text box ,once data filled to this text box on clicking click me button of popup window, i need to assign pop up text box values back to the gridview text box.
Here is my popup div(which is created using javascript function)
<div id="modal-dialog1" class="modal hide fade">
<div class="modal-header">
<button type="button" id="btnCloseModal" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3>Score Detail</h3>
<br />
<span style="color: #4F81BD">
<br />
* Use as a finding ONLY .</span>
</div>
<div class="modal-body">
<h4>Scores</h4>
<input type="text" name="AddComments" value=""/>
<button onclick="return myFunction()">Click me</button>
<hr />
</div>
</div>
i want to set the text box value back to the gridview inside myFunction() function pls help me? how can i set values to gridview inside javascript function?
回答1:
You can use the jQuery on method to bind the button click event handler and populate the textbox present inside the gridview like this:-
$("#div_History").on('click','button.btn', function (e) {
e.preventDefault();
var firstRow = $('tr:nth-child(2)', $('#GridView1'));
var outsideText = $('#txtOutside').val();
$('#txtfoo', firstRow).val(outsideText);
});
For safer side I have added a class to the button control. You can change it like this:-
<button onclick="return myFunction()" class="btn btn-primary">Click me</button>
来源:https://stackoverflow.com/questions/34224982/how-to-set-values-to-gridview-textbox-from-javascript-function