我正在使用GridView处理ASP.NET,我使用此方法可以点击它:
protected void OnRowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
GridView gr = (GridView)sender;
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.background='#3260a0';;this.style.color='white'";
e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';this.style.background='white';this.style.color='black'";
e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(RH, "Select$" + e.Row.RowIndex);
e.Row.Attributes["style"] = "cursor:pointer";
}
}
现在
我想在按下另一个按钮时禁用该功能
,但我不知道怎么做。我尝试使用Enable = false,但显然它不会影响脚本,它会让我再次点击网格。我想要的是,当我按下按钮禁用网格时,它会立即停止鼠标动画和onclick,但是没有找到合适的方法。
以下是GridView的代码,以防万一:
<asp:GridView ID="RH" runat ="server" margin-right ="auto"
margin-left="auto" OnSelectedIndexChanged="RH_SelectedIndexChanged"
OnRowDataBound ="OnRowDataBound" CssClass ="GridView" HorizontalAlign="Center"
AllowPaging="true" OnPageIndexChanging="OnPageIndexChanging" PageSize="5">
</asp:GridView>
答案 0 :(得分:0)
让你有一个禁用按钮:
<asp:Button ID="btn" runat="server" OnClick="btn_Click" Text="Disable Click" />
然后点击按钮,我们可以删除动态添加的onclick evented:
protected void btn_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in RH.Rows)
{
row.Attributes.Remove("onclick");
}
}
如果您再次需要onclick事件,请使用另一个按钮添加该属性:
protected void btn2_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in RH.Rows)
{
row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(RH, "Select$" + row.RowIndex);
}
}