2013-07-10 94 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(); 
 
     }

保護字
相關問題