GridView RowCommand event not firing

前端 未结 10 675
粉色の甜心
粉色の甜心 2020-12-06 09:42

I have a GridView that looks something like this:



        
相关标签:
10条回答
  • 2020-12-06 10:16

    You must not bind your grid on postbacks in Page_Load, only when something changed that causes the Grid to reload data(f.e. Sorting,Paging) and only in the appropriate event-handlers.

    Another possible reason: Have you disabled ViewState somewhere?

    0 讨论(0)
  • 2020-12-06 10:16

    Did them all and got nowhere then discovered this: onrowcommand="GridView1_RowCommand" on the GridView1 definition line in html.

    0 讨论(0)
  • 2020-12-06 10:18

    Tried the above answers and still could not get a post back. Ended up being a Unique ID issue. I had two <ItemTemplate> with buttons that had the same ids. (In different grid views. My second one was in a User Control)

    Changing the <asp:Button ID="" /> to a Unique ID solved the post back issue for me.

    Just thought I'd post for any one else who tried the other options with no luck.

    0 讨论(0)
  • 2020-12-06 10:18

    You can also check the HttpContext.Current.Request.Form["__EVENTTARGET"] and if it ends with the ID of the control, rebind the GridView and use Page.FindControl with the event target to find the control that fired the event

    0 讨论(0)
  • 2020-12-06 10:19

    Put the grid.Databind() inside if (!IsPostBack)

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            grid.DataBind();
        }
    }
    
    0 讨论(0)
  • 2020-12-06 10:22

    I just had a colleague who encountered the same problem; his was caused by the onrowcommand= attribute not being set in the asp:GridView element. This should be set to the name of the handler which will be handling the event.

    ... just in case someone has the same issue!

    0 讨论(0)
提交回复
热议问题