gpt4 book ai didi

c# - 取消行命令不适用于 GridView

转载 作者:太空宇宙 更新时间:2023-11-03 13:39:33 25 4
gpt4 key购买 nike

我有一个位于更新面板内的 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);
}
}

我在这里错过了什么?

最佳答案

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

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

关于c# - 取消行命令不适用于 GridView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17579767/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com