0

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

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I like this, not sure if I can use a Grid View with it or not. But will be looking into using Client Side Sorting and Paging. Just need to make sure I grab everything in the initial load.
I use datatables.net primarily with GridViews. Also, be sure to set the GridView to render with a thead element, or datatables.net will throw an error.
0

You could put it into an iframe...

3 Comments

Would that be instead of the div tags?
It would - it means it loads in it's own page etc... Whether this is suitable for your requirements, I don't know, as you haven't noted why you were doing this.
Sorry well basically the page is a statistical element in a website, that updates periodically with information from a database, and displays it in the data grid.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.