0

Clicking the button (btn_goToPoint) in my gridview is not intercepted. There is a load but the redirection does not work. When I put a breakpoint in the back code (grd_points_rowCommand), the code is not executed there. Before when I clicked on the button I had an error that I solved with "EnableEventValidation =" false "". I do not find the problem because I use exactly the same thing on other page of my application and it works.

<asp:GridView ID="grd_points" runat="server" CssClass="mydatagrid" PagerStyle-CssClass="pager"
            HeaderStyle-CssClass="header" RowStyle-CssClass="rows"
          AutoGenerateColumns="False" DataKeyNames="POI_id" 
          DataSourceID="ERP_pointsByQuestion" 
          OnRowDataBound = "grd_points_RowDataBound"
           OnRowCommand="grd_points_RowCommand">
        <Columns>
            <asp:BoundField DataField="POI_id" HeaderText="Num." ReadOnly="True" 
                SortExpression="POI_id" />
            <asp:BoundField DataField="POI_situation" HeaderText="Situation" 
                SortExpression="POI_situation" />
            <asp:BoundField DataField="c_evalPoint" HeaderText="Eval." 
                SortExpression="c_evalPoint" />
            <asp:BoundField DataField="EVA_couleur" HeaderText="Couleur" 
                SortExpression="EVA_couleur" />
            <asp:BoundField DataField="USE_cdsid" HeaderText="Responsable" 
                SortExpression="USE_cdsid" />
            <asp:BoundField DataField="POI_dateRevision" HeaderText="Date Révision" 
                SortExpression="POI_dateRevision" />

            <asp:TemplateField>
                  <ItemTemplate>
                    <asp:Button class="btn btn-primary"  ID="btn_goToPoint" runat="server" 
                      CommandName="goToPoint" 
                CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"
                      Text="►" />
                  </ItemTemplate> 
            </asp:TemplateField>

        </Columns>

And the back code:

protected void grd_points_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "goToPoint")
    {
        int index = Convert.ToInt32(e.CommandArgument);
        GridViewRow row = grd_points.Rows[index];
        string value = row.Cells[0].Text;

        Response.Redirect("gest_point.aspx?point=" + value);
    }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
baker
  • 35
  • 1
  • 9
  • Why use a RowCommand at all when the only thing you do is a Redirect? Save a PostBack, create a normal link. – VDWWD Oct 12 '17 at 07:50
  • @VDWWD: well, since he redirects to another aspx `gest_point.aspx` it's not really saving a postback. It saves lil bit server power because this page lifecycle can be skipped. – Tim Schmelter Oct 12 '17 at 07:52
  • @TimSchmelter he would when the button in the GridView is replaced by an anchor link. In order to reach `grd_points_RowCommand` there must be a PostBack first. – VDWWD Oct 12 '17 at 07:55
  • @VDWWD: but the link would also "postback" to another page on this server. So you don't save the postback but only the redirect – Tim Schmelter Oct 12 '17 at 07:59
  • @TimSchmelter, I mean a genuine anchor, not a LinkButton: ``. If you put this instead of hte `btn_goToPoint` button you'll save a PostBack. – VDWWD Oct 12 '17 at 08:01
  • @VDWWD thanks for your solution it works! I did not know the function Eval () so I had bypassed the problem thanks to c # – baker Oct 12 '17 at 08:09
  • @VDWWD: i know what you meant, but if the user clicks on that link he will call `gest_point.aspx` on the server – Tim Schmelter Oct 12 '17 at 08:15
  • @TimSchmelter that is true of course, but I was talking about the PostBack on the page that the GridView is located. That is the one you save, so instead of 2 page_load's there is only one (gest_point.aspx). – VDWWD Oct 12 '17 at 08:18

0 Answers0