我在下面的代码中使用了GridView的删除命令,但是当我按下删除命令时,网格视图中的数据将不会被刷新,实际上命令会删除该行但网格视图不会更新。我必须手动刷新浏览器,然后网格视图将更新。 标记:
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridViewDocuments_Search" runat="server" AutoGenerateColumns=False
Visible="False" onrowcommand="GridViewDocuments_Search_RowCommand"
DataKeyNames="DocID" PageSize="100" EnableSortingAndPagingCallbacks="True" >
<Columns>
<asp:TemplateField HeaderText = "Details">
<ItemTemplate>
<asp:Button ID ="btn_Show" Text="Details" runat= "server" CommandName= "Details" CommandArgument='<%#
Container.DataItemIndex%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="DocumentNo" HeaderText="DocNo" />
<asp:BoundField DataField="title" HeaderText="Title" SortExpression="title" />
<asp:BoundField DataField="Docid" HeaderText="Docid" Visible="false" />
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
代码:
protected void GridViewDocuments_Search_RowCommand(object sender, GridViewCommandEventArgs e)
{
int rowindex = Convert.ToInt32(e.CommandArgument.ToString());
_DataContext = new EDMSDataContext();
int _Docid = (int)GridViewDocuments_Search.DataKeys[rowindex].Value;
switch (e.CommandName)
{
case "Details":
Response.Redirect("~/Documentfortest.aspx?DocID=" + _Docid);
break;
case "Delete":
_DataContext.DeleteDoc(_Docid);
break;
}
var query = _DataContext.spQuickSearchDoc(txtSearchKeywords.Text);
GridViewDocuments_Search.DataSource = query;
GridViewDocuments_Search.DataBind();
}
答案 0 :(得分:0)
确保在致电DataSource
之前重新分配DataBind
媒体资源然后尝试?