使用jquery在gridview中启用禁用的复选框
本文关键字:复选框 启用 jquery gridview 使用 | 更新日期: 2023-09-27 17:49:51
我遇到了一个奇怪的情况。我无法启用一行中的复选框。
目前,我在gridview的模板字段中有一个复选框,我想在查看文档时启用它..
<asp:HyperLinkField DataNavigateUrlFormatString="/documents/{0}" DataNavigateUrlFields="document_name"
Text="View" Target="_blank" >
<ItemStyle HorizontalAlign="Center" />
</asp:HyperLinkField>
<asp:TemplateField HeaderText="Complete" SortExpression="complete">
<ItemTemplate>
<asp:CheckBox ID="gv5cbComplete" runat="server" Checked='<%# Convert.ToBoolean(Eval("complete")) %>'
OnCheckedChanged="GridView5_OnCheckedChanged" AutoPostBack="True" Enabled="False" />
</ItemTemplate>
</asp:TemplateField>
在后面的代码中,我通过行绑定向hyperlinkfield添加了一个onclick事件。
string cbid = e.Row.Cells[7].ClientID.ToString();
((HyperLink)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick", "enableGV5CheckBoxFunc('"" + cbid + "'")");
我已经注册了一个javascript jquery函数从后面的代码以及
// register script
StringBuilder cstext = new StringBuilder();
cstext.Append("<script type='"text/javascript'">" + Environment.NewLine);
cstext.Append("function enableGV5CheckBoxFunc(id){" + Environment.NewLine);
cstext.Append("window.alert(id);" + Environment.NewLine);
//cstext.Append("$('"#'" + id).removeAttr('"disabled'");" + Environment.NewLine);
cstext.Append("$('"#'" + id).prop('"disabled'", false);" + Environment.NewLine);
cstext.Append("}</script>");
cs.RegisterClientScriptBlock(cstype, csname1, cstext.ToString(), false);
现在我知道这是反过来的。如果复选框是启用的,并且我在jquery中设置了。prop(disabled, true),当我点击超链接时,它会很好地禁用复选框。然而,试图做我想做的事情并不奏效。
我需要用什么特殊的方式来做这件事吗?
感谢Ted!他使我找到了正确的方向。
I switch out
string cbid = e.Row.Cells[7].Controls[0].ClientID.ToString();
string cbid = e.Row.FindControl("gv5cbComplete").ClientID.ToString();
它起作用了。似乎是因为。net添加了一个时髦的
<span class="aspNetDisabled">
当你禁用复选框时,它会与id混淆。
谢谢!