Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Refresh Problem?

Status
Not open for further replies.

LowBrow

Technical User
Jun 1, 2001
100
US
I am new to ASP.Net, so I am not exactly sure if the above description is an accurate description of my problem.
I have 3 separate web user controls that produce similar information from my database in a gridview control. The controls list Case Manager data information filtered by (control 1) Office Location, (control 2) State Region, or (control 3) Team. Each control rests on its own page and has a dropdown list with appropriate options to filter by. So from the Case Manager menu, staff can select the link to view Case Managers by the preferred filtering method. On the Filter by Team page, the dropdown list contains the different team names, on the Region page the list contains the various State Regions, and the Office page contains the office designations.
Everything works fine until you switch from one filtering method to another. For example, if go to the filter by Team page first, the data will refresh in the gridview control correctly for however long I keep making selections. But if I then navigate to the filter by Region page, the data in the gridview will not correctly reflect the selection. If I then navigate back to the Team page, it will not reflect correct information in the gridview either.
What appears to be happening is that when I navigate from the first page to the subsequent page, the gridview control is applying the filter ID from the dropdown list to the previous field to filter by. So when I navigate from filter by Team to filter by Region, even though my dropdown list now contains Regions, the ID being refernced is applied still being applied to the TeamID field in the data. Then, when I navigate back to the Team filter page, it begins to apply the filter ID to the RegionID field.
I will post code if asked, but since the code for this is relatively extension, I think it will be more helpful initially if any of you could help me brainstorm on what may be causing this problem. I have to believe this has come up before.
I am stumped. I have rewritten this code so many times in the last week, I can almost do it blindfolded. If anyone has any insight, I would certainly appreciate it.
Thanks!
 
There's nothing from your description that I think we'll be able to help with. A cut down example of your page that illustrates the problem (so we can replicate it) will help. Alternatively, you'll have to step through the project yourself and see why the GridView doesn't contain the data you expected.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
Sounds like you have some processing that is occurring out of sequence.

What you should do... as a starting point and just to simplify... is to place all of the controls onto the same page as the grid. Set all three of the controls' AutoPostback properties = true.


NOW... What you do from here depends on if the selections in subsequent controls are dependant on prior selections. For example: if I select Dairy in the first ctrl, then I probably want to limit the next control to only dairy items like Milk. OR IS IT NOT DEPENDANT For Example: If I select the color green in the first ctrl, and the second ctrl contains a list of days of the week. (In most cases those are not dependent on each other) I believe your item lists are dependant on each other... sooo...

To simplify again, create a subroutine for each control that gets the filtered list data and binds the selection list data to the controls.
Then create a subroutine that gets the data and binds the grid.

Once you have that, figure out the order of selection process. Probably, and for this example: Ctrl1, Ctrl2 and finally Ctrl3.

In the PageLoad event create an "If IsPostback then" block and within that call the subroutine that loads Ctrl1.

Next, in each of the three controls SelectedItemChanged event, call the next respective control's subroutine. (ie: last line in Ctrl1.SelectedItemChanged will call SubCtrl2, last line in Ctrl2.SelectedItemChanged will call SubCtrl3)

Finally, SubCtrl3 will call the sub that gets the filtered data and loads the grid.

That was all pretty much fired off the hip, so there are probably some holes in it… but it should get you going down a better path.


Senior Software Developer
 
Thank you both for the responses. I have been on a different project the last day or so, and this is my first chance to get back to you.
SiriusBlackOp, I have not tried your solution yet. I wanted to post some of the code I am working with now because I think it may clear up some of the points you are directing me towards. I may not be clearly understanding what you are saying, but I have separate subroutines for each control already, and each uses its own separate stored proc. And each control has its autopostback options are set to true. The controls are not interdependant. The idea was that since we work with State agencies all across the state, staff would be able to select the most appropriate option for locating a given case manager, either by region, office location, or team assignment, depending on how much information they already possessed about the particular case manager. So here is the code. If you need more, let me know.
To me, it seems pretty straight forward. Thanks for help and comments already!

Controls - Case Offices
Code:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="CaseOffice_control_vs02.ascx.cs" Inherits="Controls_CaseOffice_control_vs02" %>
<%@ Import Namespace="NWC.CSWeb.UI" %>

        <asp:Literal ID="lblFilterSelect" runat="server" Text="Filter by:"></asp:Literal>
        <asp:DropDownList ID="ddlSelectOffice" runat="server" AutoPostBack="True" DataSourceID="objSelectOffice"
            DataTextField="CaseOfficeDesc" DataValueField="ID" AppendDataBoundItems="True">
        <asp:ListItem Value="0">All Offices</asp:ListItem>  
        </asp:DropDownList><asp:ObjectDataSource ID="objSelectOffice" runat="server" SelectMethod="GetCaseOfficeLocations"
            TypeName="NWC.CSWeb.BLL.Program.CaseOfficeLocation"></asp:ObjectDataSource>
        <br />
        <asp:GridView ID="gvwOfficeCseMgrs" runat="server" AllowPaging="True" AutoGenerateColumns="False"
            BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" CellPadding="2"
            DataSourceID="objOfficeCseMgrs" ForeColor="Black" GridLines="None">
            <FooterStyle BackColor="Tan" />
            <Columns>
                <asp:HyperLinkField DataTextField="Title" HeaderText="Name" NavigateUrl="~/ShowCaseManager.aspx" />
                <asp:BoundField DataField="CaseOffice" HeaderText="CaseOffice" SortExpression="CaseOffice" />
                <asp:BoundField DataField="CaseRegion" HeaderText="CaseRegion" SortExpression="CaseRegion" />
                <asp:BoundField DataField="CaseTeam" HeaderText="CaseTeam" SortExpression="CaseTeam" />
                <asp:CommandField ShowEditButton="True" />
                <asp:CommandField ShowDeleteButton="True" />
            </Columns>
            <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
            <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
            <HeaderStyle BackColor="Tan" Font-Bold="True" />
            <AlternatingRowStyle BackColor="PaleGoldenrod" />
        </asp:GridView>
        <asp:ObjectDataSource ID="objOfficeCseMgrs" runat="server" SelectMethod="GetOfficeCaseManagers"
            TypeName="NWC.CSWeb.BLL.Program.CaseManager">
            <SelectParameters>
                <asp:ControlParameter ControlID="ddlSelectOffice" DefaultValue="0" Name="caseOffID"
                    PropertyName="SelectedValue" Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>
Controls - Case Regions
Code:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="CaseRegion_control_vs02.ascx.cs" Inherits="Controls_CaseRegion_control_vs02" %>
<%@ Import Namespace="NWC.CSWeb.UI" %>

        <asp:Literal ID="lblFilterSelect" runat="server" Text="Select Filter:"></asp:Literal>
        <asp:DropDownList ID="ddlSelectRegion" runat="server" AppendDataBoundItems="True"
            AutoPostBack="True" DataSourceID="objSelectCaseRegions" DataTextField="RegionDesc"
            DataValueField="ID">
        <asp:ListItem Value="0">All Regions</asp:ListItem>          
        </asp:DropDownList><asp:ObjectDataSource ID="objSelectCaseRegions" runat="server"
            SelectMethod="GetCaseRegions" TypeName="NWC.CSWeb.BLL.Program.CaseRegion"></asp:ObjectDataSource>
        <br />
        <asp:GridView ID="gvwRegionCseMgrs" runat="server" AllowPaging="True" AutoGenerateColumns="False"
            BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" CellPadding="2"
            DataSourceID="objRegionCseMgrs" ForeColor="Black" GridLines="None">
            <FooterStyle BackColor="Tan" />
            <Columns>
                <asp:HyperLinkField DataTextField="Title" HeaderText="Name" />
                <asp:BoundField DataField="CaseRegion" HeaderText="CaseRegion" SortExpression="CaseRegion" />
                <asp:BoundField DataField="CaseOffice" HeaderText="CaseOffice" SortExpression="CaseOffice" />
                <asp:BoundField DataField="CaseTeam" HeaderText="CaseTeam" SortExpression="CaseTeam" />
                <asp:CommandField ShowEditButton="True" />
                <asp:CommandField ShowDeleteButton="True" />
            </Columns>
            <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
            <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
            <HeaderStyle BackColor="Tan" Font-Bold="True" />
            <AlternatingRowStyle BackColor="PaleGoldenrod" />
        </asp:GridView>
        <asp:ObjectDataSource ID="objRegionCseMgrs" runat="server" SelectMethod="GetRegionCaseManagers"
            TypeName="NWC.CSWeb.BLL.Program.CaseManager">
            <SelectParameters>
                <asp:ControlParameter ControlID="ddlSelectRegion" DefaultValue="0" Name="caseRegionID"
                    PropertyName="SelectedValue" Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>
Controls - Case Team
Code:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="CaseTeam_control_vs02.ascx.cs" Inherits="Controls_CaseTeam_control_vs02" %>
<%@ Import Namespace="NWC.CSWeb.UI" %>

<asp:Literal ID="lblFilterSelect" runat="server" Text="Filter by Team:"></asp:Literal>
        <asp:DropDownList ID="ddlSelectTeam" runat="server" AppendDataBoundItems="True"
            AutoPostBack="True" DataSourceID="objSelectCaseTeam" DataTextField="CaseTeamDesc"
            DataValueField="ID">
        <asp:ListItem Value="0">All Teams</asp:ListItem>
        
        </asp:DropDownList><asp:ObjectDataSource ID="objSelectCaseTeam" runat="server" SelectMethod="GetCaseTeams"
            TypeName="NWC.CSWeb.BLL.Program.CaseTeam"></asp:ObjectDataSource>
        <br />
        <asp:GridView ID="gvwTeamCseMgrs" runat="server" AllowPaging="True" AutoGenerateColumns="False"
            BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" CellPadding="2"
            DataSourceID="objTeamCseMgrs" ForeColor="Black" GridLines="None">
            <FooterStyle BackColor="Tan" />
            <Columns>
                <asp:HyperLinkField DataTextField="Title" HeaderText="Name" />
                <asp:BoundField DataField="CaseOffice" HeaderText="CaseOffice" SortExpression="CaseOffice" />
                <asp:BoundField DataField="CaseRegion" HeaderText="CaseRegion" SortExpression="CaseRegion" />
                <asp:BoundField DataField="CaseTeam" HeaderText="CaseTeam" SortExpression="CaseTeam" />
                <asp:CommandField ShowEditButton="True" />
                <asp:CommandField ShowDeleteButton="True" />
            </Columns>
            <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
            <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
            <HeaderStyle BackColor="Tan" Font-Bold="True" />
            <AlternatingRowStyle BackColor="PaleGoldenrod" />
        </asp:GridView>
        <asp:ObjectDataSource ID="objTeamCseMgrs" runat="server" SelectMethod="GetTeamCaseManagers"
            TypeName="NWC.CSWeb.BLL.Program.CaseManager">
            <SelectParameters>
                <asp:ControlParameter ControlID="ddlSelectTeam" DefaultValue="0" Name="caseTeamID"
                    PropertyName="SelectedValue" Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>
Collection Definitions From CaseManager.cs
Code:
       /// <summary>
        /// Returns a collection with all Case Managers for the Specified Team
        /// </summary>

        public static List<CaseManager> GetTeamCaseManagers(int caseTeamID)
        {
            if (caseTeamID <= 0)
                return GetCaseManagers();

            List<CaseManager> caseManagers = null;
            string key = "Program_CaseManagers_" + caseTeamID.ToString();

            if (BaseProgram.Settings.EnableCaching && BizObject.Cache[key] != null)
            {
                caseManagers = (List<CaseManager>)BizObject.Cache[key];
            }
            else
            {
                List<CaseManagerDetails> recordset = SiteProvider.Program.GetTeamCaseManagers(caseTeamID);
                caseManagers = GetCaseManagerListFromCaseManagerDetailsList(recordset);
                BaseProgram.CacheData(key, caseManagers);
            }
            return caseManagers;
        }

        /// <summary>
        /// Returns a collection with all Case Managers for the Specified Office
        /// </summary>

        public static List<CaseManager> GetOfficeCaseManagers(int caseOffID)
        {
            if (caseOffID <= 0)
                return GetCaseManagers();

            List<CaseManager> caseManagers = null;
            string key = "Program_CaseManagers_" + caseOffID.ToString();

            if (BaseProgram.Settings.EnableCaching && BizObject.Cache[key] != null)
            {
                caseManagers = (List<CaseManager>)BizObject.Cache[key];
            }
            else
            {
                List<CaseManagerDetails> recordset = SiteProvider.Program.GetOfficeCaseManagers(caseOffID);
                caseManagers = GetCaseManagerListFromCaseManagerDetailsList(recordset);
                BaseProgram.CacheData(key, caseManagers);
            }
            return caseManagers;
        }

        /// <summary>
        /// Returns a collection with all Case Managers for the Specified Region
        /// </summary>

        public static List<CaseManager> GetRegionCaseManagers(int caseRegionID)
        {
            if (caseRegionID <= 0)
                return GetCaseManagers();

            List<CaseManager> caseManagers = null;
            string key = "Program_CaseManagers_" + caseRegionID.ToString();

            if (BaseProgram.Settings.EnableCaching && BizObject.Cache[key] != null)
            {
                caseManagers = (List<CaseManager>)BizObject.Cache[key];
            }
            else
            {
                List<CaseManagerDetails> recordset = SiteProvider.Program.GetRegionCaseManagers(caseRegionID);
                caseManagers = GetCaseManagerListFromCaseManagerDetailsList(recordset);
                BaseProgram.CacheData(key, caseManagers);
            }
            return caseManagers;
        }
SQLProvider Calls
Code:
        /// <summary>
        /// Retrieves all Case Managers for the specified Office Location 
        /// </summary>
        public override List<CaseManagerDetails> GetOfficeCaseManagers(int caseOffID)
        {
            using (SqlConnection cn = new SqlConnection(this.ConnectionString))
            {
                SqlCommand cmd = new SqlCommand("nwc_Program_GetCaseManagersByOffice", cn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@CaseOffID", SqlDbType.Int).Value = caseOffID;

                cn.Open();
                return GetCaseManagerCollectionFromReader(ExecuteReader(cmd), false);
            }
        }

        /// <summary>
        /// Retrieves all Case Managers for the specified Region 
        /// </summary>
        public override List<CaseManagerDetails> GetRegionCaseManagers(int caseRegionID)
        {
            using (SqlConnection cn = new SqlConnection(this.ConnectionString))
            {
                SqlCommand cmd = new SqlCommand("nwc_Program_GetCaseManagersByRegion", cn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@CaseRegionID", SqlDbType.Int).Value = caseRegionID;

                cn.Open();
                return GetCaseManagerCollectionFromReader(ExecuteReader(cmd), false);
            }
        }

        /// <summary>
        /// Retrieves all Case Managers for the specified Team 
        /// </summary>
        public override List<CaseManagerDetails> GetTeamCaseManagers(int caseTeamID)
        {
            using (SqlConnection cn = new SqlConnection(this.ConnectionString))
            {
                SqlCommand cmd = new SqlCommand("nwc_Program_GetCaseManagersByTeam", cn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@CaseTeamID", SqlDbType.Int).Value = caseTeamID;

                cn.Open();
                return GetCaseManagerCollectionFromReader(ExecuteReader(cmd), false);
            }
        }
 
In case anyone else is reviewing this with a similar problem, jmeckley over in C# Microsoft solved this problem for me. Here is the answer:
-----------------------------------
your cache keys all have the same name: "Program_CaseManagers_" + #. Change the name of the cache keys to something like
Region_CaseManagers_ + # for regions
Office_CaseManagers_ + # for offices
Team_CaseManagers_ + # for teams
Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top