我已经找到了解决方案,我只想发布它,这对某些人可能有用
这是使用命令
的按钮<dxwgv:ASPxGridView ID="gdvxUsers" runat="server" AutoGenerateColumns="False" Width="100%" KeyFieldName="UserName" onrowcommand="gdvxUsers_RowCommand">
<Columns>
<dxwgv:GridViewDataTextColumn Caption="Edit" VisibleIndex="0" Width="0px">
<DataItemTemplate>
<asp:ImageButton ID="imbEdit" runat="server"
CommandName = "Edit"
ImageUrl="~/images/icon/Edit-icon.png" ClientIDMode="Static" />
</DataItemTemplate>
</dxwgv:GridViewDataTextColumn>
</dxwgv:ASPxGridView>
protected void gdvxUsers_RowCommand(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewRowCommandEventArgs e)
{
switch (e.CommandArgs.CommandName)
{
case "Edit":
break;
}
}
单击按钮时,行命令不会触发。
答案 0 :(得分:10)
问题是在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();
}
}
答案 1 :(得分:1)
您可能在网格中创建了EnableViewState="false"
。
如果是这种情况,Rowcommand Event
也不会触发。
您已在页面上EnableEventValidation="true"
。
如果是这种情况,RowCommand Event
将不会触发,请将此设置为false。
解决方案是将其设置为true。