首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RowUpdating没有在EditItemTemplate开火

RowUpdating没有在EditItemTemplate开火
EN

Stack Overflow用户
提问于 2014-10-18 23:12:41
回答 1查看 1K关注 0票数 0

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

代码语言:javascript
复制
<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之后发生的。早些时候,这片土地如下所示。

代码语言:javascript
复制
<asp:BoundField DataField="!" HeaderText="Role" />
EN

回答 1

Stack Overflow用户

发布于 2014-10-20 04:28:17

请确保指定了OnRowUpdating="gv_RowUpdating"事件,并在<%#Eval("Role") %>中更改了FieldName,请参见下面的示例:

.aspx页面

代码语言:javascript
复制
<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

代码语言:javascript
复制
protected void gv_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
   //your code here..
}

要检查完整的文章,请签出asp.net中的插入、更新、删除网格视图数据示例

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26445505

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档