简体   繁体   中英

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

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.

Is there any other way of doing this, even if it means getting rid of the GridView altogether and using a repeater and table?

Below is the code:

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;

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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