Refresh of GridView after UpdateMethod in UpdatePanel

自古美人都是妖i 提交于 2019-12-04 14:45:29

I think I see your problem. Try adding a DataKeyNames paramater to the GridView with the ID of the row you want to act on. Next remove the Triggers section as you won't need them for what you are doing. Since you are wanting to act on something change the CommandField to one of the other options such as Delete which you aren't currently using. Next modify your ObjectDataSource to define a DeleteMethod in your myNamespace.ItemMgr that accepts the Id (DataKeyNames paramater) from the GridView and performs the task you wish to perform. After the method returns it will refresh the GridView from the SelectMethod defined.

  <asp:UpdatePanel ID="UpdatePanel1" runat="server">
   <ContentTemplate>
    <asp:GridView ID="GridView1"
         runat="server"
         AllowPaging="True" 
         AllowSorting="True"
         AutoGenerateColumns="False"
         DataSourceID="ObjectDataSource1"
         PagerSettings-Visible="true" EnableViewState="False"
         DataKeyNames="Id" >
    <Columns>
        <asp:CommandField DeleteImageUrl="/images/icon.gif" 
             DeleteText="Some Text"
             ShowDeleteButton="True" 
             ButtonType="Image" />
        <asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" />
        <asp:BoundField DataField="Title" HeaderText="Title" 
             SortExpression="Title" />
    </Columns>
    </asp:GridView>
   </ContentTemplate>
  </asp:UpdatePanel>

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
    DeleteMethod="myDeleteMethod" SelectMethod="mySelectMethod" 
    TypeName="myNamespace.ItemMgr">
</asp:ObjectDataSource>

If i understand you right, you need to bind the datasource to your grid on each postback.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!