列表视图未显示上次记录何时使用asp.net删除

时间:2017-04-12 10:31:32

标签: c# asp.net

我有一个带删除的列表视图网格,说我在页面上有一个分页链接(上一页1 2下一页)。当我试图删除第二页中的最后一条记录时,listview没有显示出来。我已经在服务器端进行了绑定,并在删除记录时进行了调用。如果第二页有两个以上的记录,则显示网格。任何人都知道为什么会出现这个问题?但是当我重新加载页面显示网格时。

我有一个listview网格

<asp:ListView   ID="lvSurvey" runat="server" GroupPlaceholderID="groupPlaceHolder2"
ItemPlaceholderID="itemPlaceHolder2"  OnPagePropertiesChanging="OnPagePropertiesChangingSurvey" OnItemCommand="lvSurvey_ItemCommand"  >

---
--
</asp:ListView>

我也有分页

<asp:PlaceHolder runat="server" ID="groupPlaceHolder2"></asp:PlaceHolder>
        <tr>
            <td colspan = "3">
                <asp:DataPager ID="DataPager2" runat="server" PagedControlID="lvSurvey" PageSize="1">
                    <Fields>
                        <asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="false" ShowPreviousPageButton="true"
                            ShowNextPageButton="false" />
                        <asp:NumericPagerField ButtonType="Link" />
                        <asp:NextPreviousPagerField ButtonType="Link" ShowNextPageButton="true" ShowLastPageButton="false" ShowPreviousPageButton = "false" />
                    </Fields>
                </asp:DataPager>
            </td>
        </tr>

我能够显示来自sql server的记录以及页面中的分页显示。我在网格中有一个删除按钮

 <asp:LinkButton ID="lnkDelete" runat="server" CssClass="btn btn-danger" OnClientClick="return getConfirmation(this, 'Please confirm','Are you sure you want to delete?');"  CommandArgument='<%# Eval("Order_Survey_ID") +  "|" + Eval("Status") %>'
                            CommandName="DeleteSurveyObject"><i class="glyphicon glyphicon-trash"></i>&nbsp;</asp:LinkButton>          <br />



             </td>
        </tr>


</ItemTemplate>

    </asp:ListView>

我也可以删除并完成服务器编码的删除。但是当第二个链接中只有一条记录时,删除时无法显示列表视图。

protected void OnPagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
    {
        (lvOrderInstall.FindControl("DataPager1") as DataPager).SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
        this.GetAllOrderInstall();
      TabName.Value = "installation";

    }

  protected void lvSurvey_ItemCommand(object source, ListViewCommandEventArgs e)
        {
if(e.CommandName == "DeleteObject")
            {
                string[] param = e.CommandArgument.ToString().Split('|');
                hfInstallID.Value = param[0].ToString();

                DELETEINSTALL(int.Parse(hfInstallID.Value), clsCommon.gConstDTOMode_Delete, clsCommon.gConstActive_Status);
                GetAllOrderInstall();

                TabName.Value = "installation";
                litMsg.Text = "Record deleted successfully";
            }
       }

1 个答案:

答案 0 :(得分:0)

尝试在GetAllOrderInstall();函数末尾添加lvSurvey_ItemCommand以在更新后重新绑定列表视图。

protected void lvSurvey_ItemCommand(object source, ListViewCommandEventArgs e)
            {
                if(e.CommandName == "DeleteObject")
                {
                    string[] param = e.CommandArgument.ToString().Split('|');
                    hfInstallID.Value = param[0].ToString();

                    DELETEINSTALL(int.Parse(hfInstallID.Value), clsCommon.gConstDTOMode_Delete, clsCommon.gConstActive_Status);
                    GetAllOrderInstall();

                    TabName.Value = "installation";
                    litMsg.Text = "Record deleted successfully";
                }

                GetAllOrderInstall();
           }