Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 取消行命令不适用于GridView_C#_.net_Gridview - Fatal编程技术网

C# 取消行命令不适用于GridView

C# 取消行命令不适用于GridView,c#,.net,gridview,C#,.net,Gridview,我有一个gridview,它位于更新面板中。当我在编辑后单击“cance”时,什么也没有发生。当我调试它时,它确实进入我的gvWorkhours_row命令函数,如果,则进入取消,但屏幕上什么也没有发生(编辑字段仍然可见) 以下是我所拥有的: <asp:GridView ID="gvWorkhours" runat="server" AutoGenerateColumns="false" CssClass="GridViewStyle" OnRowEditing="gvWorkhours_

我有一个gridview,它位于更新面板中。当我在编辑后单击“cance”时,什么也没有发生。当我调试它时,它确实进入我的gvWorkhours_row命令函数,如果,则进入取消
,但屏幕上什么也没有发生(编辑字段仍然可见)

以下是我所拥有的:

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

没有返回任何数据
.......
受保护的void gvWorkhours\u行编辑(对象发送方,GridViewEditEventArgs e)
{
populateGrid();//从数据库中提取并绑定到网格
gvWorkhours.EditIndex=e.NewEditIndex;//这是要编辑的选定行
gvWorkhours.DataBind();//显示编辑模板
}
受保护的void gvWorkhours_row命令(对象发送方,GridViewCommandEventArgs e)
{
//如果GridView控件中使用了多个按钮,请使用
//CommandName属性来确定单击了哪个按钮。
如果(如CommandName==“取消”)
{
gvWorkhours.EditIndex=-1;
populateGrid();
}
}
私有void populateGrid()
{
//在此处获取所有要更新的变量。
工时wh=新工时(选择编辑项、年份、季度);
gvWorkhours.DataSource=wh.exposures;
gvWorkhours.DataBind();
}
捕获(例外情况除外)
{
lblMessage.Text=ex.Message;
//投掷(ex);
}
}

我在这里遗漏了什么?

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

    if (e.CommandName == "Cancel")
    {
        gvWorkhours.EditIndex = -1;
        populateGrid(); 
        UpdatePanel1.Update();   // whatever the name of the UpdatePanel is
    }

试着用“CancelRecord”之类的词来代替cancel,然后试着用它来回答。是的,这是一个老问题,但没有答案

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

protectedvoid gvResults\u RowCancelingEdit(对象发送方,GridViewCancelEditEventArgs e)
{
GridView gv=(GridView)发送方;
gv.EditIndex=-1;
BindGrid2();
}