Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 在EditItemTemplate中未触发行更新_Asp.net_Gridview_Edititemtemplate - Fatal编程技术网

Asp.net 在EditItemTemplate中未触发行更新

Asp.net 在EditItemTemplate中未触发行更新,asp.net,gridview,edititemtemplate,Asp.net,Gridview,Edititemtemplate,我正在将一个数组绑定到GridView。下面是我的模板字段,当我单击更新时,它不会触发行更新 <asp:TemplateField HeaderText="Role"> <EditItemTemplate> <asp:TextBox runat="server" Text='<%# Container.DataItem.ToString() %>' ID="txtEditRole"&

我正在将一个数组绑定到GridView。下面是我的模板字段,当我单击更新时,它不会触发行更新

<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" />
确保指定OnRowUpdate=gv_RowUpdate事件,并在中更改FieldName,请参见以下示例:

.aspx页


要检查完整的文章,请签出。

您是否在gridview中使用了这样的OnRowUpdate事件?是的,我使用了OnRowUpdate事件这不起作用,因为我设置了如下数据源。gridViewRoles.DataSource=Roles.GetAllRoles;因此,它给出了一个错误“System.String”不包含名为“Role”的属性。这是因为从Roles.GetAllRoles;返回的结果集中找不到Role字段;。确保在resultset中返回角色字段,并将其作为列表传递。
<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>
protected void gv_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
   //your code here..
}