[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Dataset Not Refreshing

Posted on 2007-10-01
4
Medium Priority
?
392 Views
Last Modified: 2012-05-05
I have a Wizard with about 4 WizardSteps.
First step is a simple form no problems,
second and third wizsteps are the issue

second wizard step:

has a repeater with a template and a link button on top
and a drop down list and an "add" button underneath
 - the idea is that in the database, there is a list of states assigned to a user (as determined by a session GUID) and the web user can select a state from the dropdown and press "ADD" what should happen is that the stateid gets added to the temp table and upon refresh that state is no longer available in the drop down. It should now appear in the repeater above with a linkbutton called "remove" - i think you get the picture.

==
Third wizard step:
pretty much the same as second except now we have multiple state panels with work areas inside. same add/remove interface.
===== CODE BELOW====
Partial Class user_view
    Inherits System.Web.UI.Page
    Dim pfunctions As prescient_functions
    Dim sUserId As String = Nothing

    Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
        pfunctions = New prescient_functions(Me.Session, Me.Response, Me.Request, Me)
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Response.Write("PageLoad>>")
        If Not IsNothing(Session("user_edit_guid")) Then
            Response.Write("<!--" & Session("user_edit_guid") & "-->")
        End If
        Make_State_Add_Interface()
    End Sub

    Protected Sub wUserEdit_CancelButtonClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles wUserEdit.CancelButtonClick
        gvUsers.Visible = True
        wUserEdit.ActiveStepIndex = 0
        wUserEdit.Visible = False
    End Sub

    Protected Sub gvUsers_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvUsers.SelectedIndexChanged
        Response.Write("gvUsers_SelectedIndexChanged>>")
        Dim MyGridView As GridView = CType(sender, GridView)
        wUserEdit.Visible = True
        gvUsers.Visible = False
        sUserId = gvUsers.SelectedDataKey.Value.ToString
        Dim sQuery As String = "Select * from vwUsers where userid = '" & sUserId & "'"
        wUserEdit_Visible()
        Dim dsUser As Data.DataSet = pfunctions.get_dataset(pfunctions.sConnectionString, sQuery, "user")
        userid.Text = dsUser.Tables("user").Rows(0)("userid").ToString
        first_name.Text = dsUser.Tables("user").Rows(0)("first_name").ToString
        last_name.Text = dsUser.Tables("user").Rows(0)("last_name").ToString
        email_address.Text = dsUser.Tables("user").Rows(0)("email_address").ToString

    End Sub

    Protected Sub wUserEdit_Visible()
        Response.Write("wUserEdit_Visible>>")
        Dim sQuery As String = Nothing
        Session("user_edit_guid") = pfunctions.GenerateSqlGUID()
        Session("user_edit_timestamp") = pfunctions.GenerateSqlTimeStamp()
        sQuery = "EXEC usp_User_PopulateSessionTempTable '" & gvUsers.SelectedDataKey.Value.ToString & "', '" & Session("user_edit_guid") & "', '" & Session("user_edit_timestamp") & "'"
        pfunctions.execute_query(sQuery)
    End Sub

    Protected Sub wsStates_Activate(ByVal sender As Object, ByVal e As System.EventArgs) Handles wsStates.Activate
        Response.Write("wsStates_Activate>>")
        Make_State_Add_Interface()
    End Sub

    Sub Make_State_Add_Interface()
        Dim drTempStateList As Data.SqlClient.SqlDataReader = pfunctions.get_datareader("EXEC usp_User_StateListDropDownFilter '" & Session("user_edit_guid") & "'")
        If Not drTempStateList.HasRows Then
            ddStateList.Visible = False
            btnStateAdd.Visible = False
        End If
        drTempStateList.Close()
        drTempStateList = Nothing
    End Sub

    Sub State_Add(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnStateAdd.Click
        Response.Write("State_Add>>")
        Dim sQuery As String = "INSERT INTO [temp_user_assigned_state] ([stateid], [sessionid], [timestamp]) VALUES(" _
                                & ddStateList.SelectedValue & "," _
                                & "'" & Session("user_edit_guid") & "'," _
                                & "'" & Session("user_edit_timestamp") & "')"
        pfunctions.execute_query(sQuery)
        Make_State_Add_Interface()
    End Sub

    Sub State_Remove(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim btnMyLinkButton As LinkButton = CType(sender, LinkButton)
        Dim sStateId() As String = btnMyLinkButton.ID.Split("_")
        Dim sDeleteQuery As String = "DELETE FROM [temp_user_assigned_state] WHERE ([stateid]=" & sStateId(1) & ") AND ([sessionid]='" & Session("user_edit_guid") & "') AND ([timestamp]='" & Session("user_edit_timestamp") & "')"
        Response.Write(sDeleteQuery)
        Response.Write(sStateId(0) & ":" & sStateId(1))
        pfunctions.execute_query(sDeleteQuery)
        Make_State_Add_Interface()
    End Sub

    Sub CoverageArea_Remove(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim btnMyLinkButton As LinkButton = CType(sender, LinkButton)
        Dim sCoverageAreaId() As String = btnMyLinkButton.ID.Split("_")
        Dim sDeleteQuery As String = "DELETE FROM [temp_user_assigned_coveragearea] WHERE ([coverageareaid]=" & sCoverageAreaId(1) & ") AND ([sessionid]='" & Session("user_edit_guid") & "') AND ([timestamp]='" & Session("user_edit_timestamp") & "')"
        pfunctions.execute_query(sDeleteQuery)
        Coverage_Area_Interface()
    End Sub

    Sub Coverage_Area_Interface()
        Dim pnlState As Panel = Nothing
        Dim UserEditCoverageAreaAdd As App_Controls_UserEdit_CoverageArea_DropDown
        Dim bMakeAddInterface As Boolean = False

        Dim lbCoverageAreaRemove As LinkButton = Nothing
        Dim lblCoverageAreaName As Label = Nothing
        Dim lblLineFeed As Label = Nothing
        Dim drCoverageAreas As Data.SqlClient.SqlDataReader = Nothing

        Dim drStateList As Data.SqlClient.SqlDataReader = pfunctions.get_datareader("EXEC usp_User_TempStateList '" & Session("user_edit_guid") & "'")

        wsCoverageareas.Controls.Clear()
        If Not IsNothing(drStateList) Then
            If drStateList.HasRows Then
                While drStateList.Read
                    pnlState = New Panel
                    UserEditCoverageAreaAdd = New App_Controls_UserEdit_CoverageArea_DropDown
                    drCoverageAreas = pfunctions.get_datareader("EXEC usp_User_TempCoverageAreaList '" & Session("user_edit_guid") & "', " & drStateList("stateid"))

                    If Not IsNothing(drCoverageAreas) Then
                        If drCoverageAreas.HasRows Then
                            While drCoverageAreas.Read
                                lblCoverageAreaName = New Label
                                lbCoverageAreaRemove = New LinkButton
                                lblLineFeed = New Label

                                lblCoverageAreaName.ID = "lblCoverageArea_" & drCoverageAreas("coverageareaid")
                                lblCoverageAreaName.Text = drCoverageAreas("coverage_area")
                                lblCoverageAreaName.Width = "190"
                                lblCoverageAreaName.Style.Add("margin", "2px")
                                lblCoverageAreaName.Font.Bold = True

                                lbCoverageAreaRemove.ID = "lbCoverageAreaRemove_" & drCoverageAreas("coverageareaid")
                                lbCoverageAreaRemove.Text = "[remove]"
                                AddHandler lbCoverageAreaRemove.Click, AddressOf CoverageArea_Remove

                                lblLineFeed.Text = "<br />"

                                pnlState.Controls.Add(lblCoverageAreaName)
                                pnlState.Controls.Add(lbCoverageAreaRemove)
                                pnlState.Controls.Add(lblLineFeed)
                            End While
                        End If
                    End If

                    UserEditCoverageAreaAdd.iStateId = drStateList("stateid")
                    UserEditCoverageAreaAdd.ID = "UserEditCoverageAreaAdd_" & drStateList("stateid")
                    pnlState.Controls.Add(UserEditCoverageAreaAdd)

                    pnlState.ID = drStateList("stateid")
                    pnlState.GroupingText = drStateList("state_name")
                    wsCoverageareas.Controls.Add(pnlState)
                End While
            End If
        End If
    End Sub

    Protected Sub wsCoverageareas_Activate(ByVal sender As Object, ByVal e As System.EventArgs) Handles wsCoverageareas.Activate
        Coverage_Area_Interface()
    End Sub
End Class
=====WEB FORM BELOW===
<%@ Reference Control="~/App_Controls/UserEdit_CoverageArea_DropDown.ascx" %>
<%@ Page Language="VB" MasterPageFile="~/site.master" AutoEventWireup="false" CodeFile="user_view.aspx.vb" Inherits="user_view" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="conMain" Runat="Server">
   
    User List:<br />
            <asp:GridView ID="gvUsers" runat="server" AllowPaging="True" DataKeyNames="userid" AllowSorting="True" AutoGenerateDeleteButton="false" AutoGenerateEditButton="false" AutoGenerateColumns="False" CellPadding="4" DataSourceID="dsUsers" ForeColor="#333333" GridLines="None">
                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <Columns>
                    <asp:CommandField ShowSelectButton="True" />
                    <asp:BoundField DataField="userid" HeaderText="userid" ReadOnly="True" SortExpression="userid" Visible="false" />
                    <asp:BoundField DataField="display_name" HeaderText="display_name" SortExpression="display_name" />
                    <asp:BoundField DataField="first_name" HeaderText="first_name" SortExpression="first_name" />
                    <asp:BoundField DataField="last_name" HeaderText="last_name" SortExpression="last_name" />
                    <asp:BoundField DataField="email_address" HeaderText="email_address" SortExpression="email_address" />
                </Columns>
                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                <EditRowStyle BackColor="#999999" />
                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            </asp:GridView>
           
            <asp:SqlDataSource ID="dsUsers" runat="server" ConnectionString="<%$ ConnectionStrings:csPMS_MODULE %>" DeleteCommand="DELETE FROM [user] WHERE [userid] = @userid" InsertCommand="INSERT INTO [user] ([userid], [display_name], [first_name], [last_name], [email_address], [password]) VALUES (@userid, @display_name, @first_name, @last_name, @email_address, @password)" SelectCommand="SELECT * FROM [vwUsers] WHERE roleid <> 2" UpdateCommand="UPDATE [user] SET [display_name] = @display_name, [first_name] = @first_name, [last_name] = @last_name, [email_address] = @email_address, [password] = @password WHERE [userid] = @userid" >
                <DeleteParameters>
                    <asp:Parameter Name="userid" Type="Object" />
                </DeleteParameters>
                <UpdateParameters>
                    <asp:Parameter Name="display_name" Type="String" />
                    <asp:Parameter Name="first_name" Type="String" />
                    <asp:Parameter Name="last_name" Type="String" />
                    <asp:Parameter Name="email_address" Type="String" />
                    <asp:Parameter Name="password" Type="String" />
                    <asp:Parameter Name="userid" Type="Object" />
                </UpdateParameters>
                <InsertParameters>
                    <asp:Parameter Name="userid" Type="Object" />
                    <asp:Parameter Name="display_name" Type="String" />
                    <asp:Parameter Name="first_name" Type="String" />
                    <asp:Parameter Name="last_name" Type="String" />
                    <asp:Parameter Name="email_address" Type="String" />
                    <asp:Parameter Name="password" Type="String" />
                </InsertParameters>
            </asp:SqlDataSource>
           
            <asp:Wizard ID="wUserEdit" Visible="false" runat="server" ActiveStepIndex="0" DisplayCancelButton="true" BackColor="#EFF3FB" BorderColor="#B5C7DE" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" Width="738px">
                    <StepStyle Font-Size="0.8em" ForeColor="#333333" />
            <SideBarStyle BackColor="#220377" Font-Size="0.9em" VerticalAlign="Top" />
            <NavigationButtonStyle BackColor="White" BorderColor="#507CD1" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284E98" />
            <StepNavigationTemplate>
                <asp:Button ID="StepPreviousButton" Visible="true" runat="server" CausesValidation="False" CommandName="MovePrevious" Text="Previous" />
                <asp:Button ID="StepNextButton" Visible="true" runat="server" CommandName="MoveNext" Text="Next" />
            </StepNavigationTemplate>
        <WizardSteps>
            <asp:WizardStep ID="wsUserInfo" runat="server" Title="User Info" StepType="Start">
                <div style="float: left; clear: both; margin-bottom: 10px; margin-left: 5px;">
                    <div style="float: left; clear: right; margin-left: 10px;">
                        First Name<br />
                        <asp:TextBox ID="first_name" runat="server" Width="156px"></asp:TextBox>
                    </div>
                    <asp:TextBox ID="userid" runat="server" style="visibility:hidden;" />
                </div>
                <div style="float: left; clear: both; margin-bottom: 10px; margin-left: 5px;">
                    <div style="float: left; clear: right; margin-left: 10px;">
                        Last Name<br />
                        <asp:TextBox ID="last_name" runat="server" Width="156px"></asp:TextBox>
                    </div>
                </div>
                <div style="float: left; clear: both; margin-bottom: 10px; margin-left: 5px;">
                        <div style="float: left; clear: right; margin-left: 5px;">
                              E-Mail Address *<br />
                              <asp:TextBox ID="email_address" Columns="47" runat="server" /><br />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator5" SetFocusOnError="True" runat="server" ControlToValidate="email_address" ErrorMessage="Please Enter a Value" />
                        </div>
                </div>
                <div style="float: left; clear: both; margin-bottom: 10px; margin-left: 5px;">
                        <div style="float: left; clear: right; margin-left: 5px;">
                            Role *<br />
                        <asp:DropDownList ID="roleid" runat="server" DataSourceID="dsRole" DataTextField="role_name" DataValueField="roleid" Width="163px">
                        </asp:DropDownList>
                        <asp:SqlDataSource ID="dsRole" runat="server" ConnectionString="<%$ ConnectionStrings:csPMS_MODULE %>"
                            SelectCommand="SELECT [roleid], [role_name] FROM [role] WHERE roleid <> 2"></asp:SqlDataSource>
                       
                        </div>
                    </div>
            </asp:WizardStep>
            <asp:WizardStep ID="wsStates" runat="server" Title="State(s)" StepType="Step">
                <asp:SqlDataSource ID="dsUserStateList" SelectCommand="EXEC usp_User_TempStateList @sUserEditGuid" runat="server" ConnectionString="<%$ ConnectionStrings:csPMS_MODULE %>">
                    <SelectParameters>
                        <asp:SessionParameter SessionField="user_edit_guid" Name="sUserEditGuid" />
                    </SelectParameters>
                </asp:SqlDataSource>
                <asp:Repeater ID="rUserStateList" DataSourceID="dsUserStateList" runat="server">
                    <ItemTemplate>
                        <div style="clear:both; position:relative; margin-bottom: 2px;">
                            <div style="float: left; clear: right; margin-right: 10px; width:150px;"><%# DataBinder.Eval(Container.DataItem, "state_name") %></div>
                            <div style="float: left; clear: right; margin-right: 10px;">[<asp:LinkButton ID="lbStateRemove" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "stateid") %>' Text="remove" runat="server" />]</div>
                        </div>
                    </ItemTemplate>
                </asp:Repeater>
            <br />
<%--                <asp:Panel ID="pnlStateList" runat="server" />--%>
               <asp:SqlDataSource ID="dsStateList" SelectCommand="EXEC usp_User_StateListDropDownFilter @sUserEditGuid" runat="server" ConnectionString="<%$ ConnectionStrings:csPMS_MODULE %>">
                    <SelectParameters>
                        <asp:SessionParameter SessionField="user_edit_guid" Name="sUserEditGuid" />
                    </SelectParameters>
                </asp:SqlDataSource>
                <asp:DropDownList DataSourceID="dsStateList" DataTextField="state_dropdown" DataValueField="stateid" ID="ddStateList" EnableViewState="True" runat="server" />
               
                <asp:button ID="btnStateAdd" Text="Add" runat="server" />
            </asp:WizardStep>
            <asp:WizardStep ID="wsCoverageareas" runat="server" Title="Coverage Area(s)" StepType="Finish">
           
                <%--<div style="width: 100%">
                    <div style="float: left; clear: right; margin-left: 10px;">
                        <div style="margin-bottom: 5px;">
                            Work State<br />
                            <asp:SqlDataSource ID="dsStates" runat="server" SelectCommand="SELECT * FROM (SELECT '' As state, '' AS state_fips, '(Select A State)' AS state_name UNION ALL SELECT DISTINCT zc.state, zc.state_fips, zc.state+' - '+st.state_name AS state_name FROM zipcode zc JOIN us_states st ON zc.state = st.state_abbrev) AS state ORDER BY state.state" ConnectionString="<%$ connectionstrings:csPMS_MODULE %>" />
                            <asp:DropDownList ID="state_fips" DataSourceID="dsStates" runat="server" AppendDataBoundItems="True" AutoPostBack="True" DataTextField="state_name" DataValueField="state_fips">
                            </asp:DropDownList>
                        </div>
                        <div>
                            <asp:SqlDataSource ID="dsCoverageArea" runat="server" ConnectionString="<%$ connectionstrings:csPMS_MODULE %>"
                                SelectCommand="SELECT * FROM coverage_area WHERE coverageareaid IN (SELECT DISTINCT coverageareaid FROM coverage_area_assigned_counties WHERE county_fips IN(Select DISTINCT county_fips FROM zipcode WHERE state_fips=@statefips) AND state_fips=@statefips)">
                                        <SelectParameters>
                                              <asp:ControlParameter ControlID="state_fips" Name="statefips" PropertyName="SelectedValue" Type="String" />
                                        </SelectParameters>
                                  </asp:SqlDataSource>
                            <asp:CheckBoxList DataSourceID="dsCoverageArea" DataTextField="coverage_area" DataValueField="coverageareaid" ID="coverageareaid" runat="server" />
                        </div>
                    </div>
                </div>--%>
            </asp:WizardStep>
        </WizardSteps>
                  <SideBarButtonStyle BackColor="#220377" Font-Names="Verdana" ForeColor="White" />
            <HeaderStyle BackColor="#284E98" BorderColor="#EFF3FB" BorderStyle="Solid" BorderWidth="2px" Font-Bold="True" Font-Size="0.9em" ForeColor="White" HorizontalAlign="Center" />
    </asp:Wizard>
</asp:Content>
===========================

So it seems that on the state area (i havent even gotten to the work area's yet) that the datasets  are not refreshing. I have confirmed that the data is being inserted into the database. anyone have any pointers? :)
0
Comment
Question by:EchoBinary
  • 2
  • 2
4 Comments
 
LVL 26

Expert Comment

by:Rejojohny
ID: 19993682
so which dropdown is for the state? is this the one that is not getting refreshed .. i noticed that after you add a new state you call a procedure to file the new select query .. but i do not see any refresh or rebind of the dropdown .. try the dropdown.databind after entering a new state ..

Rejo
0
 

Author Comment

by:EchoBinary
ID: 20015478
i put in Page_Load:

        rUserStateList.DataBind()
        ddStateList.DataBind()

 - but it did not refresh
0
 

Author Comment

by:EchoBinary
ID: 20015920
let me amend that-odd things-

it _does refresh - but only after 2 page_load's - example:

I add ALASKA (the page refreshes there is no alaska)
I select MARYLAND and add it (page refreshes and ALASKA is now in the list but maryland is not)
I select NEW YORK and add it (page refreshes and MARYLAND is now in the list but new york is not)

Odd, yes?
0
 
LVL 26

Accepted Solution

by:
Rejojohny earned 2000 total points
ID: 20031306
page load is fired after the event of controls .. like click event or selectedindexchanged .. so the rebind is still not happening after the new value is added by the procedure .. so the bevior that oyu are currently seeing is not "odd", but as expected .. to solve this, you need to rebind after the SP to add the new value is called ..
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month20 days, 4 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question