Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.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 我无法在gridview中编辑_Asp.net_Entity Framework_Gridview - Fatal编程技术网

Asp.net 我无法在gridview中编辑

Asp.net 我无法在gridview中编辑,asp.net,entity-framework,gridview,Asp.net,Entity Framework,Gridview,我正在使用linq to entity我已经添加了gridview,但它没有编辑,当我调试它时,它不会访问方法GridView5_rowUpdate()。。这是网格视图的代码 <asp:GridView ID="GridView5" runat="server" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="CustomerId"

我正在使用linq to entity我已经添加了gridview,但它没有编辑,当我调试它时,它不会访问方法GridView5_rowUpdate()。。这是网格视图的代码

<asp:GridView ID="GridView5" runat="server" AllowSorting="True" 
            AutoGenerateColumns="False" CellPadding="4" DataKeyNames="CustomerId" 
            DataSourceID="SqlDataSource3" ForeColor="#333333" GridLines="None" 
            onrowupdating="GridView5_RowUpdating">
            <AlternatingRowStyle BackColor="White" />
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                <asp:BoundField DataField="CustomerId" HeaderText="CustomerId" 
                    InsertVisible="False" ReadOnly="True" SortExpression="CustomerId" />
                <asp:BoundField DataField="FirstName" HeaderText="FirstName" 
                    SortExpression="FirstName" />
                <asp:BoundField DataField="LastName" HeaderText="LastName" 
                    SortExpression="LastName" />
                <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
            </Columns>
            <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
            <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
            <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
            <SortedAscendingCellStyle BackColor="#FDF5AC" />
            <SortedAscendingHeaderStyle BackColor="#4D0000" />
            <SortedDescendingCellStyle BackColor="#FCF6C0" />
            <SortedDescendingHeaderStyle BackColor="#820000" />
        </asp:GridView>


当我试图手动插入所需的字段验证器时,我需要字段验证器。当我删除所需的字段验证器时,有人能告诉我发生了什么吗?

首先,您需要在gridview上实现事件以启用编辑,MSDN定义:

在单击行的“编辑”按钮时发生,但在 GridView控件进入编辑模式

ASPX:

<asp:GridView 
        ID="gvCustomers" 
        runat="server" 
        OnRowEditing="gvCustomers_RowEditing">
protected void gvCustomers_RowEditing(object sender, GridViewEditEventArgs e)
{
    gvCustomers.EditIndex = e.NewEditIndex;
    //Re bind the grid view
}
现在,如果在网格视图上单击“编辑”链接时未触发此事件,则表示页面上存在阻止回发的验证逻辑

解决此问题的最佳方法是为导致问题的验证控件(而不是gridview)设置
ValidationGroup
属性:


<div id="insertEmployee">
        <asp:TextBox ID="txtName" runat="server" ValidationGroup="Insert" />
        <asp:RequiredFieldValidator ID="rfvName" runat="server" ControlToValidate="txtName" ErrorMessage="Name is required" ValidationGroup="Insert" />
        <asp:Button ID="btnAdd" runat="server" Text="Add" ValidationGroup="Insert" />
    </div>