ASP.Net
中Gridview
Visual Studio 2013
面临一个非常奇怪的问题,就是当我点击Update
上的gridview
链接时行,我无法重置网格。如果有人以前遇到过这个问题,请建议。
我更加好奇,因为这一直工作到昨天,然后突然停止工作。所有其他事件仍然完美无缺。
我的gridview
页面上有一个aspx
控件,标题定义如下
<asp:GridView ID="gvTeam" runat="server" AllowSorting="True"
AutoGenerateEditButton="True" AutoGenerateDeleteButton="True"
OnRowEditing="tblTeam_RowEditing" AutoGenerateColumns="False"
OnRowUpdating="gvTeam_RowUpdating" OnRowCancelingEdit="gvTeam_RowCancelingEdit"
OnRowDataBound="gvTeam_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="id" Visible="false">
<ItemTemplate>
<asp:HiddenField ID="member_id" runat="server" Value='<%# Eval("id") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ZSName" HeaderText="Name" ReadOnly="true" />
<asp:BoundField DataField="ZSLevel" HeaderText="Level" ReadOnly="true" />
<asp:TemplateField HeaderText="Is Admin?">
<EditItemTemplate>
<asp:DropDownList ID="ddlIsAdmin" runat="server">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblIsAdmin" runat="server" Text='<%# Eval("IsAdmin") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Office" HeaderText="Office" ReadOnly="true" />
<asp:BoundField DataField="LastUpdated" HeaderText="Last Updated" ReadOnly="true" />
<asp:TemplateField HeaderText="Is Active?">
<EditItemTemplate>
<asp:DropDownList ID="ddlIsActive" runat="server">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblIsActive" runat="server" Text='<%# Eval("Active") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="email" HeaderText="Email Id" ReadOnly="true" />
<asp:TemplateField HeaderText="Space Id" Visible="false">
<ItemTemplate>
<asp:HiddenField ID="space_id" runat="server" Value='<%# Eval("space_id") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
以下是我为行更新事件编写的代码
protected void gvTeam_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
Response.Write("hello");
gvTeam.EditIndex = -1;
gvTeam.DataBind();
}
下面的行编辑代码:
protected void tblTeam_RowEditing(object sender, GridViewEditEventArgs e)
{
int index = e.NewEditIndex;
//LoadTeamDetails();
gvTeam.EditIndex = index;
gvTeam.DataBind();
}
答案 0 :(得分:0)
将代码更改为
<asp:GridView ID="gvTeam" runat="server" AllowSorting="True"
OnRowEditing="tblTeam_RowEditing" AutoGenerateColumns="False"
OnRowUpdating="gvTeam_RowUpdating" OnRowCancelingEdit="gvTeam_RowCancelingEdit"
OnRowDataBound="gvTeam_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="id" Visible="false">
<ItemTemplate>
<asp:HiddenField ID="member_id" runat="server" Value='<%# Eval("id") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ZSName" HeaderText="Name" ReadOnly="true" />
<asp:BoundField DataField="ZSLevel" HeaderText="Level" ReadOnly="true" />
<asp:TemplateField HeaderText="Is Admin?">
<EditItemTemplate>
<asp:DropDownList ID="ddlIsAdmin" runat="server">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblIsAdmin" runat="server" Text='<%# Eval("IsAdmin") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Office" HeaderText="Office" ReadOnly="true" />
<asp:BoundField DataField="LastUpdated" HeaderText="Last Updated" ReadOnly="true" />
<asp:TemplateField HeaderText="Is Active?">
<EditItemTemplate>
<asp:DropDownList ID="ddlIsActive" runat="server">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblIsActive" runat="server" Text='<%# Eval("Active") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="email" HeaderText="Email Id" ReadOnly="true" />
<asp:TemplateField HeaderText="Space Id" Visible="false">
<ItemTemplate>
<asp:HiddenField ID="space_id" runat="server" Value='<%# Eval("space_id") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="false">
<EditItemTemplate>
<asp:LinkButton ID="btnUpdate" CssClass="btnupdate" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton>
<asp:LinkButton ID="btncancel" CssClass="btncancel" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="lbtnedit" CssClass="btnedit" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" />
<asp:LinkButton ID="btnDelete" CssClass="btndelete" runat="server" CausesValidation="False" CommandName="Delete"
OnClientClick="return confirm('Are you sure you want to delete this record?')" Text="Delete"
CommandArgument='<%# Eval("ID") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>