RowUpdating未在EditItemTemplate中触发

时间:2014-10-18 23:12:41

标签: asp.net gridview edititemtemplate

我将数组绑定到GridView。下面是我的模板字段,当我点击更新时它不会触发RowUpdating。

<asp:TemplateField HeaderText="Role">
                <EditItemTemplate>
                    <asp:TextBox runat="server" Text='<%# Container.DataItem.ToString() %>' ID="txtEditRole"></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <%# Container.DataItem.ToString() %>
                </ItemTemplate>
            </asp:TemplateField>

这是在将场地交给TempleteField之后发生的。早些时候,这个领域就像下面一样。

<asp:BoundField DataField="!" HeaderText="Role" />

1 个答案:

答案 0 :(得分:0)

确保您在OnRowUpdating="gv_RowUpdating"中指定<%#Eval("Role") %>事件并更改 FieldName ,请参阅此示例:

.aspx页面

<asp:GridView ID="gv" runat="server" DataKeyNames="Id" AutoGenerateColumns="false" OnRowEditing="gv_RowEditing"      
OnRowUpdating="gv_RowUpdating" OnRowCancelingEdit="gv_RowCancelingEdit" OnRowCommand="gv_RowCommand" OnRowDeleting="gv_RowDeleting">
<Columns>
   <asp:TemplateField>
     <EditItemTemplate>
       <asp:LinkButton ID="lbtnUpdate" runat="server" CommandName="Update" Text="Update" />
       <asp:LinkButton ID="lbtnCancel" runat="server" CommandName="Cancel" Text="Cancel" />
     </EditItemTemplate>
     <ItemTemplate>
        <asp:LinkButton ID="lbtnEdit" runat="server" CommandName="Edit" Text="Edit" />
        <asp:LinkButton ID="lbtnDelete" runat="server" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure you want to delete this record?')" CausesValidation="false" />
     </ItemTemplate>    
  </asp:TemplateField>
  <asp:TemplateField HeaderText="Role">
     <EditItemTemplate>
       <asp:TextBox ID="txtEditRole" runat="server" Text='<%#Eval("Role") %>' />
     </EditItemTemplate>
     <ItemTemplate>
       <asp:Label ID="lblRole" runat="server" Text='<%#Eval("Role") %>' />
     </ItemTemplate>    
  </asp:TemplateField>
</Columns>
</asp:GridView>

<强> .aspx.cs

protected void gv_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
   //your code here..
}

要查看完整文章,请结帐insert, update, delete gridview data example in asp.net