[英]How to toggle a gridview templated asp button text using jquery or javascript
I have a gridview where one column is an "Add" / "Remove" asp:button which I would like to toggle the text when clicked with either jquery or javascript. 我有一个gridview,其中一列是“添加” /“删除” asp:按钮,当我用jquery或javascript单击时,我想切换文本。 I have not been able to locate a good example for this. 我无法为此找到一个很好的例子。
Here is my markup for the template field: 这是我对模板字段的标记:
<asp:TemplateField HeaderText="ADD <br /> REMOVE" HeaderStyle-ForeColor="White" >
<ItemTemplate >
<asp:Button id="btnBuy" runat="server" Width="50px" Height="15px" BorderStyle="Solid" Text="ADD" Font-Size="7pt" BackColor="#FFFF80" />
</ItemTemplate>
<HeaderStyle Width="7%" />
<ItemStyle CssClass="sessionItems" VerticalAlign="Middle" HorizontalAlign="Center" />
</asp:TemplateField>
Here is some jquery but it doesn't work as I expect this is more for a single button: 这是一些jquery,但是它不起作用,因为我希望这对于单个按钮来说更多:
$('#btnBuy').click(function()
{
if ($(this).text() == "ADD")
{
$(this).text("REMOVE");
} else {
$(this).text("ADD");
}
})
Please advise how to correctly toggle the gridview button text? 请告知如何正确切换gridview按钮文本?
Thank you, Jim 谢谢吉姆
Here is my checkbox and it does not post back: 这是我的复选框,它不会回发:
<asp:TemplateField HeaderText="Select <br /> Files" HeaderStyle-ForeColor="White" >
<ItemTemplate >
<asp:CheckBox ID="chkSelectVideo" runat="server" OnClick="checkboxClicked(this)" ToolTip="Select file for download"
Enabled='<%# Eval("SORD_EnableSelectionCheckBox") %>' Checked='<%# Eval("SORD_SelectedForDownloadFlag") %>' />
</ItemTemplate>
<HeaderStyle Width="6%" />
<ItemStyle VerticalAlign="Middle" HorizontalAlign="Center" />
</asp:TemplateField>
One thing what you could try is in the OnClientClick event of the button, call a function as shown below 您可以尝试做的一件事是在按钮的OnClientClick事件中,调用如下所示的函数
OnClientClick="SomeJSFunction(this)" OnClientClick =“ SomeJSFunction(this)”
In this way you get access to your button control in the JS Function, so now you can modify the text of the button in the function as shown below: 通过这种方式,您可以访问JS函数中的按钮控件,因此现在您可以修改函数中按钮的文本,如下所示:
function SomeJSFunction(source) {
if (source.value === 'Add') {
source.value = 'Remove';
} else if (source.value === 'Remove') {
source.value = 'Add';
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.