2

我有一个位于更新面板内的gridview。当我在编辑后单击“取消”时,没有任何反应。当我调试它确实进入我的 gvWorkhours_RowCommand 函数和取消if中,但屏幕上没有任何反应(编辑字段仍然可见)

这是我所拥有的:

<asp:GridView ID="gvWorkhours" runat="server" AutoGenerateColumns="false" CssClass="GridViewStyle" OnRowEditing="gvWorkhours_RowEditing"  
 OnRowCommand="gvWorkhours_RowCommand"  >
<EmptyDataTemplate>
no data returned
</EmptyDataTemplate>
<Columns>
<asp:commandfield buttontype="Link" showeditbutton="true" edittext="Edit" />
     <asp:TemplateField HeaderText="Organization">
        <ItemTemplate>
            <%# Eval("org.orgCode").ToString() + "- " + Eval("org.orgSubCode").ToString()%>
        </ItemTemplate>
    </asp:TemplateField>
 <asp:TemplateField HeaderText="Year-Qtr">
        <ItemTemplate>
            <%# Eval("year").ToString() + "- " + Eval("qtr").ToString()%>
        </ItemTemplate>
    </asp:TemplateField>
.......






 protected void gvWorkhours_RowEditing(Object sender, GridViewEditEventArgs e)
    {
        populateGrid();  //pulls from the Db and binds to the grid
        gvWorkhours.EditIndex = e.NewEditIndex;  //This is the selected row to edit
        gvWorkhours.DataBind();  //Make the edit Template show up

    }

    protected void gvWorkhours_RowCommand(Object sender, GridViewCommandEventArgs e)
    {
        // If multiple buttons are used in a GridView control, use the
        // CommandName property to determine which button was clicked.
        if (e.CommandName == "Cancel")
        {
            gvWorkhours.EditIndex = -1;
            populateGrid(); 
        }

    }





private void populateGrid()
    {
        //getting all variables for update here.
            Workhours wh = new Workhours(selectedItem, year, qtr);
            gvWorkhours.DataSource = wh.exposures;
            gvWorkhours.DataBind();
        }
        catch (Exception ex)
        {
            lblMessage.Text = ex.Message;
            //  throw(ex);
        }
    }

我在这里想念什么?

4

3 回答 3

1

您的示例中没有显示 UpdatePanel,所以我不知道您是如何设置它的,但如果您UpdateMode设置为Conditional,您可能需要手动调用Update更新面板上的方法:

    if (e.CommandName == "Cancel")
    {
        gvWorkhours.EditIndex = -1;
        populateGrid(); 
        UpdatePanel1.Update();   // whatever the name of the UpdatePanel is
    }
于 2013-07-11T04:11:46.657 回答
0

尝试给出除取消之外的其他单词,例如“CancelRecord”,然后尝试使用它

于 2013-07-11T04:36:00.830 回答
0

是的,这是一个老问题,但没有答案。

取消需要在 RowCancelEdit 方法中......似乎“取消”在这种情况下是一个受保护的词

        protected void gvResults_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            GridView gv = (GridView)sender;
            gv.EditIndex = -1;
            BindGrid2();
        }

于 2018-01-24T17:12:00.420 回答