单击按钮后,Rowcommand不会触发

我已经找到了解决方案,我只想发布它,这对某些人来说可能有用

这是使用命令的按钮

        

  protected void gdvxUsers_RowCommand(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewRowCommandEventArgs e) { switch (e.CommandArgs.CommandName) { case "Edit": break; } } 

单击按钮时,行命令不会触发。

问题是在Page_Load我在gridview上使用Databind()命令我正在使用rowcommand ,似乎在DataBind()rowcommand被取消了。

  protected void Page_Load(object sender, EventArgs e) { gdvxUsers.DataSource = GetAllUserAndRole(); gdvxUsers.DataBind(); } 

所以我通过仅在第一次加载时绑定数据来解决此问题。

  protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { gdvxUsers.DataSource = GetAllUserAndRole(); gdvxUsers.DataBind(); } } 

您可能在网格EnableViewState="false"

如果是这种情况, Rowcommand Event也不会触发。

您已在页面上使EnableEventValidation="true"

如果是这种情况, RowCommand Event将不会RowCommand Event ,将此设置为false。

解决方案是将其设置为true。