简体   繁体   English

Asp.Net GridView排序单独的页面

[英]Asp.Net GridView Sorting Separate Page

I have an issue with having a asp.net Grid View loaded into a div tag on a page (UI/Host.aspx). 我在将asp.net网格视图加载到页面(UI / Host.aspx)的div标签中时遇到问题。 The Grid View itself is on a seperate page (GridViews/GridView1.aspx) and I'm using the jQuery load() function to load this page into the div tag. 网格视图本身在单独的页面(GridViews / GridView1.aspx)上,我正在使用jQuery load()函数将此页面加载到div标记中。

My problem is when sorting the grid view it tries to postback to the page that's hosting it, and comes back with the error "Unable to find page UI/GridView1.aspx", is there a way to override this so that it post backs to itself, (which I assumed it would but doesn't) or is there an easier way to do the sorting. 我的问题是,在对网格视图进行排序时,它尝试回发到承载它的页面,并返回错误“无法找到页面UI / GridView1.aspx”,是否有一种方法可以覆盖它,以便回发到本身(我认为会但不会)或是否有更简单的方法来进行排序。

Is there any other way of doing this, even if it means getting rid of the GridView altogether and using a repeater and table? 还有其他方法可以做到这一点,即使这意味着完全摆脱GridView并使用转发器和表也是如此吗?

Below is the code: 下面是代码:

UI/Hosts.aspx UI / Hosts.aspx


  //jQuery to load the div with the page UI/Hosts.aspx
  $(document).ready(function() {
    StartRefresh();
  });

function startRefresh() { refreshID = setInterval(function() { DisplayDate(); $("#divDests").load("../GridViews/Gridview1.aspx?ConfigID=" + $("#ctl00_MainContent_dlConfiguration").val() + "&ModuleID=" + $("#ctl00_MainContent_ddlModule").val()); }, $("#ctl00_MainContent_ddlRefresh :selected").val()); }

GridViews/Gridview1.aspx; GridViews / Gridview1.aspx;

//Markup for GridViews/Gridview1.aspx
<html>
<head><title></title></head>
<body>

<form runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <asp:UpdatePanel ID="up1" runat="server">
        <ContentTemplate>


    <br />
    <asp:GridView Font-Size="8.7pt" ID="gvLiveDest" runat="server" AutoGenerateColumns="False" 
        EmptyDataText="No Records Found" AllowSorting="true" 
        onsorting="gvLiveDest_Sorting" onrowcreated="gvLiveDest_RowCreated" OnRowDataBound="gvLiveDest_RowDataBound">
        <Columns>                    
            <asp:TemplateField HeaderText="Name" SortExpression="DestinationName" HeaderStyle-CssClass="centralalignment">
                <ItemTemplate>
                    <asp:Label ID="lblDescription" runat="server" Text='<%# WebHelper.HTMLSafe(Eval("Description")) %>' ToolTip='<%# WebHelper.HTMLSafe(Eval("Description")) %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Logged &lt;br /&gt; In" HeaderStyle-CssClass="centralalignment" SortExpression="LoggedIn" >
                <ItemStyle CssClass="centralalignment" />
                <ItemTemplate>
                    <asp:Label ID="lblLoggedIn" runat="server" Text='<%# SetLoggedIn(Convert.ToBoolean(Eval("Active"))) %>'></asp:Label>
                 </ItemTemplate>
             </asp:TemplateField>
             <asp:TemplateField HeaderText="Current&lt;br /&gt;Status" HeaderStyle-CssClass="centralalignment" SortExpression="LastStatus" >
                <ItemStyle CssClass="centralalignment" />
                <ItemTemplate>
                    <asp:Label ID="lblCurrentStatus" runat="server" Text='<%# WebHelper.HTMLSafe(Eval("LastStatus")) %>' ToolTip='<%#Eval("LastStatus") %>' />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Time in&lt;br /&gt;Current&lt;br /&gt;Status" HeaderStyle-CssClass="centralalignment" SortExpression="CurrentDuration">
                <ItemStyle CssClass="RightAlignment" />
                <ItemTemplate>
                    <asp:Label ID="lblCurrentTime" runat="server" Text='<%# ICT.DAL.Reporting.CallDurFormat(Eval("CurrentDuration")) %>' />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="Lines" HeaderText="Lines" HeaderStyle-CssClass="centralalignment" SortExpression="Lines" 
                ItemStyle-CssClass="centralalignment" />
            <asp:BoundField DataField="LinesBusy" HeaderText="Lines &lt;br /&gt; Busy" HeaderStyle-CssClass="centralalignment" 
                ItemStyle-CssClass="centralalignment" ReadOnly="True" HtmlEncode="False" SortExpression="LinesBusy" />
            <asp:BoundField DataField="LinesAvailable" HeaderStyle-CssClass="centralalignment" 
                ItemStyle-CssClass="centralalignment" SortExpression="LinesAvailable" 
                HeaderText="Lines &lt;br /&gt; Available" HtmlEncode="false" ReadOnly="True" />                            
            <asp:TemplateField HeaderText="Last Call Time" SortExpression="Timestamp" HeaderStyle-CssClass="centralalignment">
                <ItemTemplate>
                    <asp:Label ID="lblLastCallTime" runat="server" Text='<%# WebHelper.HTMLSafe(Eval("LastCallTime")) %>' ToolTip='<%# WebHelper.HTMLSafe(Eval("LastCallTime")) %>'></asp:Label>
                 </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

            </ContentTemplate>
    </asp:UpdatePanel>
</form>

</body>
</html>

And the onSort Event Code (However it never hits this) 还有onSort事件代码(但是从来没有碰到过)

protected void gvLiveDest_Sorting(object sender, GridViewSortEventArgs e)
{
    if (string.Compare(e.SortExpression, ViewState["SortField"].ToString(), true) == 0)
    {
        _sortDir = (_sortDir == "ASC") ? "DESC" : "ASC";
    }
    else
        _sortDir = "ASC";

    _SortField = e.SortExpression;
    ViewState["SortField"] = e.SortExpression;
    ViewState["sortDir"] = _sortDir;

    BindLiveDestination();
}

I switched over to client-side paging/sorting a while ago and haven't been happier. 不久前,我切换到客户端分页/排序 ,但从此不高兴了。 Of course, you would need to set AllowSorting="false" and AllowPaging="false" in your GridView. 当然,您需要在GridView中设置AllowSorting="false"AllowPaging="false"

您可以将其放入iframe中...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM