Link to home
Start Free TrialLog in
Avatar of nbotts
nbotts

asked on

How do I link back to the same recordset that a person paged to

Hello Experts,

I have a datagrid with a hyperlink that takes the user to a page with several related detailsviews that are shown to the user through a MultiView.

I want to be able to return a user back to the datagrid to the same place that they paged to retrieve their original request. The datagrid has many pages of records so I don't want them to have to start on page 1 each time so just pointing them back to that page doesn't work. I tried using "javascript:history.back()" but if the user cycles through the MultiViews then they keep going back through each view before finally returning to the page.

Is there a hyperlink control or javascript that can do this?

Thanks,

Nathan
Avatar of jmwheeler
jmwheeler

You can handle this a couple of ways.

You can add the current page index to the query string and then have the details page return that page index to the main page.  Then modify your main page to check for the query string parameter when loading the data.

When you change the page you can store the current page index in Session then change your data load to check for that Session value when loading the data.
Avatar of nbotts

ASKER

Ok, let me work on that a bit to see if I can figure out how to set that up.
Avatar of nbotts

ASKER

Well I messed around a little bit, but couldn't seem to get jmwheeler's suggestion to come through.

In the meantime I am using "javascript:window.history.go(-1);return false;" That handles the postback issue at least.
<asp:GridView ID="MyGrid" ............ />

protected void Page_Load(object sender, EventArgs e)
{
     if (!IsPostBack)
         BindData()    
}

protected void YourCodeToHandlePageEvent(object sender, GridViewPageEventArgs e)
{
     //Your code to handle page event
    Session["PageIndex"] = e.NewPageIndex;
    //Your code to rebind data
}
protected void BindData()
{
    MyGrid.DataSource = .......
    MyGrid.DataBind = ...........
    if (Session["PageIndex"] != null)
    {
        MyGrid.PageIndex = (Int32)Session["PageIndex"];
        Session.Remove["PageIndex"];
    }
    else
    {
         //Your other paging code
    }
}
Avatar of nbotts

ASKER

Thank you for that jmwheeler. Just a little more hand holding please...

Below is the general code (removed specifics for ease of reading) from the first page (viewServices.aspx) that has a GridView with a HyperLink column that passes a couple variables in the QueryString to the details page (Notes.aspx) which a user can then tab through MultiViews of related data from the chosen record.

The attached Code Snippet is the code for the second page (Notes.aspx) and its related MultiViews and DetailsViews (again minus general details).

I think I generally understand the logic, but am not sure where to correctly place some of the code. Also a bit confused as to what the "MyGrid.DataBind = ........"  should reference.

Thanks again. - Nathan

-------------------------------------------------------------------------------------------------------------------

The first page (viewServices.aspx) is as follows:

<%@ Page Language="C#" MasterPageFile="~/AppMaster.master" Title="Clinic Services" %>

<asp:Content ID="Content1" ContentPlaceHolderID="phMain" runat="Server">
    <h2>
        View Patients<br />
    </h2>
    <p>
        <strong>Choose Clinic:&nbsp;<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" DataSourceID="ClinicEntitlementDataSource"
            DataTextField="Clinic" DataValueField="ClinicID">
        </asp:DropDownList><asp:SqlDataSource ID="ClinicEntitlementDataSource" runat="server"
            ConnectionString="<%$ ConnectionStrings:ApplicationConnectionString1 %>" SelectCommand="SELECT * FROM [nav_ClinicEntitlements_tbl] WHERE ([UserName] = @UserName)">
            <SelectParameters>
                <asp:ProfileParameter Name="UserName" PropertyName="UserName" Type="Object" />
            </SelectParameters>
        </asp:SqlDataSource>
        </strong>
    </p>
    <p>
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
            AutoGenerateColumns="False" CellPadding="4" DataKeyNames="patientID,carePlanID" DataSourceID="SqlDataSource2"
            ForeColor="#333333" GridLines="None" EmptyDataText="No enrolled patients are currently assigned to this clinic.">
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <Columns>
                <asp:HyperLinkField DataNavigateUrlFields="carePlanID, patientID" DataNavigateUrlFormatString="Notes.aspx?carePlanID={0}&patientID={1}"
                    HeaderText="Care Plan" Text="CP" />
            </Columns>
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#999999" />
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConflictDetection="CompareAllValues"
        </asp:SqlDataSource>
    </p>
<%@ Page Language="C#" MasterPageFile="~/AppMaster.master" Title="Care Plan" %>
    
<asp:Content ID="Content1" ContentPlaceHolderID="phMain" runat="Server">
 
<script runat="server">
    
    // Controls Multiview menu
 
    protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
    {
        int index = Int32.Parse(e.Item.Value);
        MultiView1.ActiveViewIndex = index;
    }
 
    // Grabs carePlanId and inserts into new encounter
 protected void EncounterDetailsView_ItemInsert(object sender, DetailsViewInsertEventArgs e)
        {
            e.Values["carePlanID"] = Convert.ToInt32(Request.QueryString["carePlanID"]);
       }
    // Grabs encounterID and inserts into new step
    protected void StepsDetailsView_ItemInsert(object sender, DetailsViewInsertEventArgs e)
    {
        e.Values["encounterID"] = Convert.ToInt32(EncounterDetailsView.SelectedValue);
        
    }
 
    </script>
 
 <p><a href="#" onclick="javascript:window.history.go(-1);return false;"> <<< Previous</a></p>
    
    
    <asp:Menu
        id="Menu1"
        Orientation="Horizontal"
        StaticMenuItemStyle-CssClass="tab"
        StaticSelectedStyle-CssClass="selectedTab"
        CssClass="tabs"
        OnMenuItemClick="Menu1_MenuItemClick"
        Runat="server" BackColor="#F7F6F3" DynamicHorizontalOffset="2" 
        Font-Names="Verdana" Font-Size="0.8em" ForeColor="#7C6F57" 
        StaticSubMenuIndent="10px">
        <Items>
        <asp:MenuItem Text="Care Plan" Value="0" Selected="True" />
        <asp:MenuItem Text="Encounter Notes" Value="1" />
        <asp:MenuItem Text="Goals" Value="2" />
        <asp:MenuItem Text="Profile" Value="3" />
        </Items>    
        <StaticSelectedStyle CssClass="selectedTab" BackColor="#5D7B9D" 
            ForeColor="White" />
        <StaticMenuItemStyle CssClass="tab" HorizontalPadding="5px" VerticalPadding="2px" />
        <DynamicHoverStyle BackColor="#7C6F57" ForeColor="White" />
        <DynamicMenuStyle BackColor="#F7F6F3" />
        <DynamicSelectedStyle BackColor="#5D7B9D" />
        <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
        <StaticHoverStyle BackColor="#7C6F57" ForeColor="White" />
    </asp:Menu>
    
    <div class="tabContents">
    
    <asp:MultiView
        id="MultiView1"
        ActiveViewIndex="0"
        Runat="server">
        <asp:View ID="View1" runat="server">
        
    <p>
        <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
            CellPadding="5" DataKeyNames="carePlanID" DataSourceID="CarePlanDataSource" ForeColor="#333333"
            GridLines="None" Height="50px" Width="75%" CellSpacing="5">
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" VerticalAlign="Top" Width="20%" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <Fields>           
            </Fields>
            <HeaderTemplate>Care Plan: <%# Eval("firstName") %> <%#Eval("lastName") %></HeaderTemplate>
            <HeaderStyle BackColor="LightSlateGray" Font-Bold="False" ForeColor="White" Font-Size="Large" />
            <EditRowStyle BackColor="#999999" />
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        </asp:DetailsView>
        <asp:SqlDataSource ID=DataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationConnectionString1 %>"
        </asp:SqlDataSource>
    </p>
        </asp:View>        
        <asp:View ID="View2" runat="server">
    <p>
        <asp:DetailsView ID="DetailsView2" runat="server" AllowPaging="True" AutoGenerateRows="False"
            DataKeyNames="encounterID,carePlanID" DataSourceID="EncounterNotesDataSource" Height="50px" Width="75%" CellPadding="5" ForeColor="#333333" GridLines="None" BorderStyle="Solid" CellSpacing="5" OnItemInserting="EncounterDetailsView_ItemInsert">
            <Fields>
            </Fields>
            <HeaderTemplate>Encounter Notes: <%# Eval("firstName") %> <%#Eval("lastName") %></HeaderTemplate>
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" Width="25%" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <HeaderStyle BackColor="LightSlateGray" Font-Bold="False" ForeColor="White" Font-Size="Large" />
            <EditRowStyle BackColor="#999999" />
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    
        </asp:DetailsView>
        <asp:SqlDataSource ID="DataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationConnectionString1 %>"
        </asp:SqlDataSource>
    </p>
    <p>
        &nbsp;</p>
        </asp:View>        
        <asp:View ID="View3" runat="server">
            <p>
            <asp:DetailsView ID="DetailsView3" runat="server" AllowPaging="True" AutoGenerateRows="False"
                DataKeyNames="careplanStepsID,encounterID" DataSourceID="StepsDataSource" Height="50px" Width="75%" CellPadding="5" ForeColor="#333333" GridLines="None" BorderStyle="Solid" HeaderText="Care Plan Steps" CellSpacing="5" OnItemInserting="StepsDetailsView_ItemInsert">
                <Fields>
                    
                </Fields>
                <HeaderTemplate>Progress Steps: <%# Eval("firstName") %> <%# Eval("lastName") %></HeaderTemplate>
                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" Width="15%" />
                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                <HeaderStyle BackColor="LightSlateGray" Font-Bold="False" ForeColor="White" Font-Size="Large" />
                <EditRowStyle BackColor="#999999" />
                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            </asp:DetailsView>
            <asp:SqlDataSource ID="DataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationConnectionString1 %>"
            </asp:SqlDataSource>
           </p>
        </asp:View>   
        <asp:View ID="View4" runat="server">
        <p>
            <asp:DetailsView ID="DetailsView4" runat="server" AutoGenerateRows="False" 
                BorderStyle="Solid" CellPadding="5" CellSpacing="5" DataKeyNames="patientID" 
                DataSourceID="PatientDataSource" ForeColor="#333333" GridLines="None" 
                HeaderText="Patient Profile" Height="50px" Width="75%">
                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" Width="15%" />
                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                <Fields>                </Fields>
                <HeaderTemplate>Patient Profile: <%# Eval("firstName") %> <%# Eval("lastName") %></HeaderTemplate>
                <HeaderStyle BackColor="LightSlateGray" Font-Bold="False" ForeColor="White" Font-Size="Large" />
            <EditRowStyle BackColor="#999999" />
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            </asp:DetailsView>
            <asp:SqlDataSource ID="DataSource4" runat="server">
 
            </asp:SqlDataSource>
        </p>
            <p>
                &nbsp;</p>
            <p>
                &nbsp;</p>
        </asp:View>     
    </asp:MultiView>
    </div>
    
</asp:Content>

Open in new window

I made some adjustments based on the way you have coded your app.  Don't worry about my previous post this one should be all you need.

Add this property to GridView1:   OnPageIndexChanged="GridView1_PageIndexChanged"

Add the following to your ViewServices.aspx

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
       if (!IsPostBack && Session["PageIndex"] != null)
            try { GridView1.PageIndex = (Int32)Session["PageIndex"]; }
            catch {}  //Take no action
    }

    protected void GridView1_PageIndexChanged(object sender, DataGridPageChangedEventArgs e)
    {
        Session["PageIndex"] = e.NewPageIndex;
    }
</script>
Avatar of nbotts

ASKER

Thanks jmwheeler.

I added that code and it gives me the following error: No overload for 'GridView1_PageIndexChanged' matches delegate 'System.EventHandler'

and points to this line as the source error: <asp:GridView ID="GridView1" runat="server" OnPageIndexChanged="GridView1_PageIndexChanged"

I searched this and found some discussions on using the correct delegates, but it appears as though the correct ones are already being used.

Any suggestions?
ASKER CERTIFIED SOLUTION
Avatar of jmwheeler
jmwheeler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nbotts

ASKER

Fantastic! That did the trick. Thanks for helping me work through this.

This will make things much smoother.

Much appreciated,

Nathan
Avatar of nbotts

ASKER

Fantastic! That did the trick. Thanks for working through this with me.

This will make things much smoother.

Much appreciated ~ Nathan