简体   繁体   English

更改asp.net中的文本框值

[英]change textbox value in asp.net

I am using this gridview, I have one header checkbox and one column containing textbox. 我正在使用此gridview,我有一个标题复选框和一个包含文本框的列。 I want that when i check the header checkbox the value of every textbox changes from 0 to 1. 我希望当我选中标题复选框时,每个文本框的值都从0更改为1。

<asp:GridView ID="grdData" runat="server" style="Text-align:center;">
  <Columns>
    <asp:TemplateField>
      <ItemTemplate>
        <asp:CheckBox ID="CheckBox1" runat="server" />
      </ItemTemplate>
      <HeaderTemplate>
        <asp:CheckBox ID="CheckBox2" runat="server" OnClick="CheckAllEmp(this)"/>
      </HeaderTemplate>
    </asp:TemplateField>
    <asp:TemplateField>
      <HeaderTemplate>
        <asp:Label ID="Status_Header" runat="server" Text="Status" />
      </HeaderTemplate>
      <ItemTemplate>
        <asp:TextBox ID="TextBox1" runat="server" Text="0"></asp:TextBox>
      </ItemTemplate>
    </asp:TemplateField>
  </Columns>
</asp:GridView>

You can do this by using Jquery. 您可以使用Jquery做到这一点。

Not tested with the actual data, but hope this should work for you. 未使用实际数据进行测试,但希望这对您有用。

 $(function () {
        $('#CheckBox2').change(function () {
            $("#TextBox1").val(($(this).is(':checked')) ? "1" : "0");
        });
    });

Also you must need to add jquery plugin right before the javascript code which I gaved u. 另外,您还必须在我给您的JavaScript代码之前添加jquery插件。 Below is one of the plugin which you can use 以下是您可以使用的插件之一

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>

Do let us know if it works or not 让我们知道它是否有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM