How to set values to gridview textbox from javascript function

一个人想着一个人 提交于 2019-12-24 12:48:28

问题


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">&times;</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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!