Rowcommand do not fire after clicking button
Asked Answered
S

2

7

I have already find out the solution, i just want to post it so this may be useful for some people

This is the button that use command

<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;
        }
    }

The Row Command is not fire when the button is clicked.

Similarity answered 7/7, 2011 at 5:30 Comment(0)
S
10

The Problem is that on Page_Load I use Databind() command on the gridview I'm using rowcommand, it seems that after DataBind(), rowcommand is cancelled.

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

So I fix this problem by binding data only on first load.

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            gdvxUsers.DataSource = GetAllUserAndRole();
            gdvxUsers.DataBind();
        }
    }
Similarity answered 7/7, 2011 at 5:33 Comment(0)
R
1

You may have made EnableViewState="false" in grid.

If this is the case, Rowcommand Event will also not fire.

You have made EnableEventValidation="true" on page.

If this is the case, RowCommand Event Will Not Fire, Set This To false.

The solution is to set it to true.

Rhonarhonchus answered 28/2, 2012 at 14:21 Comment(2)
The Enable ViewState was the key for me, thanks a mill.Graehme
I posted this six years ago and i don't work on ASP.NET Webform anymore but thanks for your reply. This would be useful for other people :)Similarity

© 2022 - 2024 — McMap. All rights reserved.