2017-04-12 72 views
0

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

我有一个列表视图网格,

<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> 

我也能删除,也做服务器编码deletion.But当只有一个第二路段记录,不能够在删除时显示列表视图。

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"; 
      } 
     } 
+0

绑定代码隐藏你的列表视图中'如果(!的IsPostBack)' – Valkyrie

+0

它不工作,我已经给这个代码 – aniltc

+0

u能指https://www.aspsnippets.com/Articles/ Display-Show-data-in-ListView-from-database-in-ASPNet-using-C-and-VBNet.aspx这个链接 –

回答

0

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

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(); 
      } 
+0

这就像早期,但当我正在做一些它如何进去。谢谢你的帮助 – aniltc

+0

欢迎花花公子。对不起,我没有得到你想要评论的内容:)。我认为这个问题是在删除记录后,你并没有更新列表视图。 –

相关问题