如何使用javascript将一个文本框值复制到asp.net gridview中的另一个文本框?

时间:2012-10-09 14:40:10

标签: asp.net gridview

我无法复制或自动绑定到第二个文本框。我需要处理哪个事件,onkeyuponblur

这是我的代码:

<script type="text/javascript">    
    function OneTextToother()   
    { 
    var first=document.getElementById(txtQuantity).value;    
    document.getElementById(txtQuantity1).value=first; 
    }     
</script>

<asp:GridView ID="gvOrder" runat="server" OnRowDataBound="gvOrder_RowDataBound">       
<Columns>              
<asp:TemplateField>                   
<ItemTemplate>                    
<asp:TextBox ID="txtQuantity" runat="server" onkeyup="javascript:OneTextToother();" >
</asp:TextBox>                    
</ItemTemplate>                                
</asp:TemplateField>     
<asp:TemplateField>                  
<ItemTemplate>                
 <asp:TextBox ID="txtQuantity1" runat="server" ></asp:TextBox>               
</ItemTemplate>                              
</asp:TemplateField>          
</Columns>        
</asp:GridView>

1 个答案:

答案 0 :(得分:1)

您可以使用Client Id property

<%# ((GridViewRow)Container).FindControl("txtQuantity1").ClientID %>

所以

var first = document.getElementById('<%# ((GridViewRow)Container).FindControl("txtQuantity").ClientID %>');

document.getElementById('<%# ((GridViewRow)Container).FindControl("txtQuantity1").ClientID %>').value=first;