2013-07-10 120 views
1

我有一个更新面板内的gridview。当我在编辑后点击“取消”时,没有任何反应。当我调试它进入我的gvWorkhours_RowCommand功能和内取消if,但没有任何反应在屏幕上(编辑框都还可见)取消行命令不适用于GridView

这里是我有:

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

我是什么在这里失踪?

回答

1

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

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

试举其他词不是取消,如“CancelRecord”,然后尝试用它

0

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

取消需求是在一个RowCancelEdit方法......似乎“取消”在这种情况下

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

保护字
相关问题