Answered by:
Gridview not loading on page load

Question
-
User-1767698477 posted
I am using a details view in the far right column to populate the rows of the gridview in the main window. What happens is the page will load the detailsview, and if I click on a paging link (2) the gridview will then load. I want the gridview to load automatically with the very first record without having to click on the pager of the details view. How do I tell the gridview to load based on the first record from the details view control without clicking on the paging link?
Imports System.Data.Sql Imports System.Data.SqlClient Imports System.Web.UI.WebControls Imports System.Web.Security Imports System.Net.Mail Imports DataSet1TableAdapters Partial Class users_Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then If Session("Username") = Nothing Then lblName.Text = "You have been logged out <br>due to inactivity - Please login again" Exit Sub End If lblName.Text = Session("Firstname") & " " & Session("Lastname") Dim UserProfileTableAdapter As New DataSet1TableAdapters.UserProfilesTableAdapter Session("Folder") = UserProfileTableAdapter.GetOriginatorFolder(Session("OriginatorID")) End If 'Clear these when returing to the grid 'Session("OriginatorID") = "" Session("docpath") = "" Session("Borfirst") = "" Session("Borlast") = "" End Sub Protected Sub DetailsView1_ItemCommand(sender As Object, e As CommandEventArgs) Dim lbl As Label = DirectCast(DetailsView1.FindControl("Label1"), Label) Dim originatorguid As Guid originatorguid = Guid.Parse(lbl.Text) Session("OriginatorID") = originatorguid Dim UserProfileTableAdapter As New DataSet1TableAdapters.UserProfilesTableAdapter Session("Folder") = UserProfileTableAdapter.GetOriginatorFolder(Session("OriginatorID")) DetailsView1.DataBind() 'Each time we change the originator ID, need to update the folder for the path End Sub Protected Sub GridView2_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView2.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then 'e.Row.Cells(1).Text = "<i>" & e.Row.Cells(1).Text & "</i>" Dim Last As String = e.Row.Cells(1).Text Dim social As String = e.Row.Cells(2).Text Dim SSN As String = e.Row.Cells(2).Text If Len(e.Row.Cells(2).Text) = 9 Then SSN = SSN.Substring(5, 4) e.Row.Cells(2).Text = "-" & SSN End If Dim datesubmitted As String = e.Row.Cells(3).Text If datesubmitted = "1/1/1900 12:00:00 AM" Then e.Row.Cells(3).Text = "Unsubmitted" e.Row.Cells(4).Enabled = False 'Create DU button is enabled by default when page loads unless changed here Else If datesubmitted <> "1/1/1900 12:00:00 AM" Then 'find the first whitespace character Dim i As Int16 = InStr(datesubmitted, " ") If i <> 0 Then datesubmitted = datesubmitted.Substring(0, i - 1) 'truncate to just a date e.Row.Cells(3).Text = datesubmitted End If End If End If If Left(SSN, 1) = "-" Then SSN = SSN.Substring(1, 4) ' remove the - character End If 'get the Folder since this is a processor Dim lbl1 As Label = CType(e.Row.FindControl("LblDUfilecreationdate"), Label) ' Dim hl As HyperLink = CType(e.Row.FindControl("Hyperlink3"), HyperLink) Dim path As String = "C:/mortgageloanapply/users/" + Session("Folder").ToString + "/" + Last + SSN + "/" + Last + SSN + ".fnm" 'need to modify this line for server 'Dim path As String = "h:\root\home\pacwest-001\www\MortgageLoanApply\users\" & Session("Folder").ToString + "\" + Last + SSN + "\" + Last + SSN + ".fnm" 'need to modify this line for server 'hl.NavigateUrl = "./" + Session("Folder") + "/" + Last + SSN + ".fnm" 'need to modify this line for server If System.IO.File.Exists(path) Then lbl1.Text = System.IO.File.GetLastWriteTime(path) Else lbl1.Text = "Not Created" 'hl.Text = "Not Created" 'hl.Enabled = False End If End If End Sub Protected Sub GridView2_PageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs) GridView2.PageIndex = e.NewPageIndex GridView2.DataBind() End Sub Protected Sub GridView2_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) ' Retrieve the row index stored in the CommandArgument property. If e.CommandName = "CreateDUfile" Then Dim appid As Integer = Convert.ToInt32(e.CommandArgument) CreateDUFILE(appid) End If End Sub Protected S
Monday, May 25, 2020 2:37 AM
Answers
-
User-1767698477 posted
At the moment, upon login, the gridview is not loading any rows. The details view displays record 1 which is Test company and there is one paging link for record #2. The details view displays the correct guid for Test company (503841a3-c615-4e4d-8cf5-20fbddbf7a7f) When you click a paging link in the details view, the gridview should load the rows for the guid which is displayed. I made this label control visible so you can so the guid. Rather than paste images here, you can login to see this live at my site. It you go to mortgageloanapply.com and login as janedoe with the password (case sensitive) Janedoe1* you will see that the details view and the label display Test Company. The gridview should be loading with 3 rows though. If you click on the 2 in the paging of the details view, the gridview will load with the wrong company. There are only 2 companies right now. 1 and 2. Clicking the 2 should bring up JD Company and display 11 rows. It displays instead the 3 rows of Test Company. So they are reversed! 1 shows 2 and 2 shows 1. Each time you click a details view page, the sql query should be based on the OriginatorID in the detailsview and the gridview should bind on this. The gridview is loading the items that agree with the label above it, but the details view is showing the other company. Can you help?
Dim UserProfileTableAdapter As New DataSet1TableAdapters.UserProfilesTableAdapter Dim UserProfile As DataSet1.UserProfilesDataTable If Not IsPostBack Then If Session("Username") = Nothing Then lblName.Text = "You have been logged out <br>due to inactivity - Please login again" Exit Sub End If lblName.Text = Session("Firstname") & " " & Session("Lastname") UserProfile = UserProfileTableAdapter.GetLOsbyprocessorID(Session("UserID")) For Each userprofilerow As DataSet1.UserProfilesRow In UserProfile Session("OriginatorID") = userprofilerow.UserID Session("Folder") = userprofilerow.Folder Label2.Text = "Applications for " & userprofilerow.Firstname & " " & userprofilerow.Lastname & " at " & userprofilerow.Company 'DetailsView1.DataBind() GridView2.DataBind() Exit For 'just get the first record Next 'Session("Folder") = UserProfileTableAdapter.GetOriginatorFolder(Session("OriginatorID")) 'where processorID-UserID will get all the row in userprofiles where a LO has the processor assigned. 'then just grab the first record and exit the next End If 'Clear these when returing to the grid Session("OriginatorID") = "" Session("docpath") = "" Session("Borfirst") = "" Session("Borlast") = "" End Sub Protected Sub DetailsView1_ItemCommand(sender As Object, e As CommandEventArgs) Dim lbl As Label = DirectCast(DetailsView1.FindControl("Label1"), Label) Dim originatorguid As Guid originatorguid = Guid.Parse(lbl.Text) Session("OriginatorID") = originatorguid Dim UserProfileTableAdapter As New DataSet1TableAdapters.UserProfilesTableAdapter Dim UserProfile As DataSet1.UserProfilesDataTable UserProfile = UserProfileTableAdapter.GetData(Session("OriginatorID")) For Each userprofilerow As DataSet1.UserProfilesRow In UserProfile Label2.Text = "Applications for " & userprofilerow.Firstname & " " & userprofilerow.Lastname & " at " & userprofilerow.Company Next Session("Folder") = UserProfileTableAdapter.GetOriginatorFolder(originatorguid) GridView2.DataBind() 'DetailsView1.DataBind() End Sub
<%@ Page Title="" Language="VB" MasterPageFile="~/templates/default1.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="users_Default" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> <title>Member Home Page</title> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <div id="menu" class="container"> </div> </asp:Content> <asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="Server"> <br /> <table align="center" width="95%"> <tr> <td align="left"> Welcome : <b> <asp:Label ID="lblName" runat="server" Text="" ForeColor="#FFB30F"></asp:Label></b> </td> <td> </td> <td align="right"> <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="change_password.aspx">Change Password</asp:HyperLink> </td> </tr> <tr> <td align="left"> <asp:LoginView ID="LoginView1" runat="server"> <LoggedInTemplate> Logged in as : <asp:LoginName ID="LoginName1" runat="server" Font-Bold="True" /> </LoggedInTemplate> <AnonymousTemplate> Your are not logged in. <br /> Click the login link to sign in. </AnonymousTemplate> </asp:LoginView> </td> <td> </td> <td align="right"> <asp:HyperLink ID="HyperLink4" runat="server" NavigateUrl="edit_profile.aspx">Edit Profile</asp:HyperLink> </td> </tr> <tr> <td align="left"> <asp:LoginStatus ID="LoginStatus1" runat="server" LogoutAction="Redirect" LogoutPageUrl="~/Logout.aspx" /> </td> <td align="center"> <h2> Loan Applications </h2> </td> <td align="right"> </td> </tr> </table> <br /> <br /> <br /> <asp:Label ID="Label2" runat="server" Text=""></asp:Label> <center> <br /> <asp:GridView ID="GridView2" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource2" OnRowDataBound="Gridview2_rowdatabound" OnRowCommand="Gridview2_Rowcommand" OnPageIndexChanging="GridView2_PageIndexChanging" CellPadding="3" ForeColor="Black" GridLines="Vertical" Width="95%" RowStyle-HorizontalAlign="Center" PagerStyle-HorizontalAlign="NotSet" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px"> <AlternatingRowStyle BackColor="#CCCCCC" /> <Columns> <asp:BoundField DataField="borfirst" HeaderText="First" SortExpression="borfirst" /> <asp:BoundField DataField="borlast" HeaderText="Last" SortExpression="borlast" /> <asp:BoundField DataField="borssn" HeaderText="SSN" SortExpression="borssnt" /> <asp:BoundField DataField="appcomplete" HeaderText="App Date" SortExpression="appcomplete" /> <asp:TemplateField ShowHeader="False" HeaderText="Create File"> <ItemTemplate> <asp:Button runat="server" Text="Create DU file" ID="CreateDUfile" CommandName="CreateDUfile" CommandArgument='<%#Bind("applicantid") %>'></asp:Button> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="3.2 File"> <ItemTemplate> <asp:Label ID="LblDUfilecreationdate" runat="server" Text=""></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField ShowHeader="False" HeaderText="Revise"> <ItemTemplate> <asp:Button ID="EditApp" Text="App" runat="server" OnCommand="Editcommand" CommandName="Editapp" CommandArgument='<%#Bind("applicantid") %>'></asp:Button> </ItemTemplate> </asp:TemplateField> <asp:TemplateField ShowHeader="False" HeaderText="Upload"> <ItemTemplate> <asp:Button ID="Upload" Text="Docs" runat="server" OnCommand="Uploadcommand" CommandName="Upload" CommandArgument='<%#Bind("applicantid") %>'></asp:Button> </ItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#CCCCCC" /> <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" /> <RowStyle /> <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" /> <SortedAscendingCellStyle BackColor="#F1F1F1" /> <SortedAscendingHeaderStyle BackColor="#808080" /> <SortedDescendingCellStyle BackColor="#CAC9C9" /> <SortedDescendingHeaderStyle BackColor="#383838" /> </asp:GridView> <br /> <asp:Label ID="Lblresult" runat="server" Text="" Visible="false" ForeColor="#0033CC"></asp:Label> </center> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:sqlConnectionString %>" SelectCommand="SELECT applicantID, userid, borfirst, borlast, borssn, appcomplete FROM loanapps WHERE (userid = @userid) AND (appcomplete <> '1900-01-01 00:00:00.000')"> <SelectParameters> <asp:SessionParameter Name="userid" SessionField="OriginatorID" /> </SelectParameters> </asp:SqlDataSource> <br /> <br /> </asp:Content> <asp:Content ID="Content4" ContentPlaceHolderID="ContentPlaceHolder3" runat="Server"> <div id="Div1" class="container"> <asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" CellSpacing="2" DataKeyNames="UserID" DataSourceID="SqlDataSource1" Height="50px" Width="300px" ForeColor="Black" OnItemCommand="DetailsView1_ItemCommand" GridLines="Horizontal" Font-Bold="True" > <EditRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" /> <Fields> <asp:BoundField DataField="Company" HeaderText="Company : " SortExpression="Company" HeaderStyle-HorizontalAlign="Right" HeaderStyle-Width="130" /> <asp:BoundField DataField="CompanyNMLS" HeaderText="Company NMLS : " SortExpression="CompanyNMLS" HeaderStyle-HorizontalAlign="Right" /> <asp:BoundField DataField="Firstname" HeaderText="First : " SortExpression="Firstname" HeaderStyle-HorizontalAlign="Right" /> <asp:BoundField DataField="Lastname" HeaderText="Last : " SortExpression="Lastname" HeaderStyle-HorizontalAlign="Right" /> <asp:BoundField DataField="Title" HeaderText="Title : " SortExpression="Title" HeaderStyle-HorizontalAlign="Right" /> <asp:BoundField DataField="NMLS" HeaderText="NMLS : " SortExpression="NMLS" HeaderStyle-HorizontalAlign="Right" /> <asp:BoundField DataField="Phone" HeaderText="Phone : " SortExpression="Phone" HeaderStyle-HorizontalAlign="Right" /> <asp:TemplateField> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Eval("UserID") %>' CommandArgument='<%# Eval("UserID") %>' Visible="true"></asp:Label> </ItemTemplate> </asp:TemplateField> </Fields> <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" /> <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" BorderStyle="Double" /> <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" /> <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" /> </asp:DetailsView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:sqlConnectionString %>" SelectCommand="SELECT UserID, Company, CompanyNMLS, Firstname, Lastname, Title, NMLS, Phone, ProcessorID, Processor, Processoremail, ProcessorDob, ProcessorInfo, Folder, Subscription, TrialStart, SubscriptionStart, SubscriptionEnd FROM UserProfiles WHERE (ProcessorID = @ProcessorID)"> <SelectParameters> <asp:SessionParameter Name="ProcessorID" SessionField="UserID" Type="Object" /> </SelectParameters> </asp:SqlDataSource> </div> </asp:Content>
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, June 3, 2020 6:23 AM
All replies
-
User288213138 posted
Hi sking,
I am using a details view in the far right column to populate the rows of the gridview in the main window. What happens is the page will load the detailsview, and if I click on a paging link (2) the gridview will then load. I want the gridview to load automatically with the very first record without having to click on the pager of the details view. How do I tell the gridview to load based on the first record from the details view control without clicking on the paging link?According to your description, I cannot reproduce your problem.
Please post your aspx code.
And I didn't find any data binding to Gridview in your code behind.
Best regards,
Sam
Tuesday, May 26, 2020 1:58 AM -
User-1767698477 posted
<%@ Page Title="" Language="VB" MasterPageFile="~/templates/default1.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="users_Default" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> <title>Member Home Page</title> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <div id="menu" class="container"> </div> </asp:Content> <asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="Server"> <br /> <table align="center" width="95%"> <tr> <td align="left"> Welcome : <b> <asp:Label ID="lblName" runat="server" Text="" ForeColor="#FFB30F"></asp:Label></b> </td> <td> </td> <td align="right"> <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="change_password.aspx">Change Password</asp:HyperLink> </td> </tr> <tr> <td align="left"> <asp:LoginView ID="LoginView1" runat="server"> <LoggedInTemplate> Logged in as : <asp:LoginName ID="LoginName1" runat="server" Font-Bold="True" /> </LoggedInTemplate> <AnonymousTemplate> Your are not logged in. <br /> Click the login link to sign in. </AnonymousTemplate> </asp:LoginView> </td> <td> </td> <td align="right"> <asp:HyperLink ID="HyperLink4" runat="server" NavigateUrl="edit_profile.aspx">Edit Profile</asp:HyperLink> </td> </tr> <tr> <td align="left"> <asp:LoginStatus ID="LoginStatus1" runat="server" LogoutAction="Redirect" LogoutPageUrl="~/Logout.aspx" /> </td> <td align="center"> <h2> Loan Applications</h2> </td> <td align="right"> <asp:Button ID="NewApp" Text="Start New Application" runat="server" OnCommand="ClearSessionCommand" CommandName="ClearSession"></asp:Button> </td> </tr> </table> <br /> <center> <br /> <asp:GridView ID="GridView2" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource2" OnRowDataBound="Gridview2_rowdatabound" OnRowCommand="Gridview2_Rowcommand" OnPageIndexChanging="GridView2_PageIndexChanging" CellPadding="3" ForeColor="Black" GridLines="Vertical" Width="95%" RowStyle-HorizontalAlign="Center" PagerStyle-HorizontalAlign="NotSet" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px"> <AlternatingRowStyle BackColor="#CCCCCC" /> <Columns> <asp:BoundField DataField="borfirst" HeaderText="First" SortExpression="borfirst" /> <asp:BoundField DataField="borlast" HeaderText="Last" SortExpression="borlast" /> <asp:BoundField DataField="borssn" HeaderText="SSN" SortExpression="borssnt" /> <asp:BoundField DataField="appcomplete" HeaderText="App Date" SortExpression="appcomplete" /> <asp:TemplateField ShowHeader="False" HeaderText="Checklist"> <ItemTemplate> <asp:Button ID="Checklist" Text="Checklist" runat="server" OnCommand="Checklistcommand" CommandName="Checklist" CommandArgument='<%#Bind("applicantid") %>'></asp:Button> </ItemTemplate> </asp:TemplateField> <asp:TemplateField ShowHeader="False" HeaderText="Create File"> <ItemTemplate> <asp:Button runat="server" Text="Create DU file" ID="CreateDUfile" CommandName="CreateDUfile" CommandArgument='<%#Bind("applicantid") %>'></asp:Button> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="3.2 File"> <ItemTemplate> <span onmouseout="UnTip()" onmouseover="Tip('You must set your processor information in your user profile before you can send du files.', WIDTH, 172, BGCOLOR, '#eeeeee')"> <asp:Image ID="helpicon" runat="server" Visible="false" ImageUrl="~/templates/images/help.gif"></asp:Image> </span> <asp:Button ID="NotifyProcessor" Text="Email Processor" runat="server" OnCommand="Emailprocessor" CommandName="Emailprocessor" CommandArgument='<%#Bind("applicantid") %>'></asp:Button> </ItemTemplate> </asp:TemplateField> <asp:TemplateField ShowHeader="False" HeaderText="Revise"> <ItemTemplate> <asp:Button ID="EditApp" Text="App" runat="server" OnCommand="Editcommand" CommandName="Editapp" CommandArgument='<%#Bind("applicantid") %>'></asp:Button> </ItemTemplate> </asp:TemplateField> <asp:TemplateField ShowHeader="False" HeaderText="Upload"> <ItemTemplate> <asp:Button ID="Upload" Text="Docs" runat="server" OnCommand="Uploadcommand" CommandName="Upload" CommandArgument='<%#Bind("applicantid") %>'></asp:Button> </ItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#CCCCCC" /> <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" /> <RowStyle /> <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" /> <SortedAscendingCellStyle BackColor="#F1F1F1" /> <SortedAscendingHeaderStyle BackColor="#808080" /> <SortedDescendingCellStyle BackColor="#CAC9C9" /> <SortedDescendingHeaderStyle BackColor="#383838" /> </asp:GridView> <br /> <asp:Label ID="Lblresult" runat="server" Text="" Visible="false" ForeColor="#0033CC"></asp:Label> </center> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:sqlConnectionString %>" SelectCommand="SELECT [applicantid], [userid], [borfirst], [borlast], [borssn], [appcomplete] FROM [loanapps] WHERE ([userid] = @userid)"> <SelectParameters> <asp:SessionParameter Name="userid" SessionField="userID" /> </SelectParameters> </asp:SqlDataSource> <br /> <br /> </asp:Content> <asp:Content ID="Content4" ContentPlaceHolderID="ContentPlaceHolder3" runat="Server"> </asp:Content>
Wednesday, May 27, 2020 7:11 AM -
User288213138 posted
Hi sking,
How do I tell the gridview to load based on the first record from the details view control without clicking on the paging link?Protected Sub DetailsView1_ItemCommand(sender As Object, e As CommandEventArgs) Dim lbl As Label = DirectCast(DetailsView1.FindControl("Label1"), Label) Dim originatorguid As Guid originatorguid = Guid.Parse(lbl.Text) Session("OriginatorID") = originatorguid Dim UserProfileTableAdapter As New DataSet1TableAdapters.UserProfilesTableAdapter Session("Folder") = UserProfileTableAdapter.GetOriginatorFolder(Session("OriginatorID")) DetailsView1.DataBind()
In your aspx page, I didn't find DetailsView, please post the complete aspx code.
Best regards,
Sam
Thursday, May 28, 2020 3:19 AM -
User-1767698477 posted
Sorry, here is the code:
<div id="Div1" class="container"> <asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" CellSpacing="2" DataKeyNames="UserID" DataSourceID="SqlDataSource1" Height="50px" Width="300px" ForeColor="Black" OnItemCommand="DetailsView1_ItemCommand" GridLines="Horizontal" Font-Bold="True"> <EditRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" /> <Fields> <asp:BoundField DataField="Company" HeaderText="Company : " SortExpression="Company" HeaderStyle-HorizontalAlign="Right" HeaderStyle-Width="130" /> <asp:BoundField DataField="CompanyNMLS" HeaderText="Company NMLS : " SortExpression="CompanyNMLS" HeaderStyle-HorizontalAlign="Right" /> <asp:BoundField DataField="Firstname" HeaderText="First : " SortExpression="Firstname" HeaderStyle-HorizontalAlign="Right" /> <asp:BoundField DataField="Lastname" HeaderText="Last : " SortExpression="Lastname" HeaderStyle-HorizontalAlign="Right" /> <asp:BoundField DataField="Title" HeaderText="Title : " SortExpression="Title" HeaderStyle-HorizontalAlign="Right" /> <asp:BoundField DataField="NMLS" HeaderText="NMLS : " SortExpression="NMLS" HeaderStyle-HorizontalAlign="Right" /> <asp:BoundField DataField="Phone" HeaderText="Phone : " SortExpression="Phone" HeaderStyle-HorizontalAlign="Right" /> <asp:TemplateField> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Eval("UserID") %>' CommandArgument='<%# Eval("UserID") %>' Visible="false"></asp:Label> </ItemTemplate> </asp:TemplateField> </Fields> <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" /> <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" BorderStyle="Double" /> <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" /> <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" /> </asp:DetailsView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:sqlConnectionString %>" SelectCommand="SELECT UserID, Company, CompanyNMLS, Firstname, Lastname, Title, NMLS, Phone, ProcessorID, Processor, Processoremail, ProcessorDob, ProcessorInfo, Folder, Subscription, TrialStart, SubscriptionStart, SubscriptionEnd FROM UserProfiles WHERE (ProcessorID = @ProcessorID)"> <SelectParameters> <asp:SessionParameter Name="ProcessorID" SessionField="UserID" Type="Object" /> </SelectParameters> </asp:SqlDataSource> </div>
Saturday, May 30, 2020 4:31 AM -
User-943250815 posted
Just a guess.
Seems at some point you don´t have UserID defined, perhaps in page load.
Be sure you have UserID already set on page load other than SQLDataSource will not return any record, this way there will no records rendered on gridview.When you click on paging, looks UserID is defined then Gridview.Dababind does the job.
If I´m correct even pushing Gridview.DataBind on Page Load, there will be no records on GridviewSaturday, May 30, 2020 5:01 PM -
User288213138 posted
Hi sking,
I am using a details view in the far right column to populate the rows of the gridview in the main window. What happens is the page will load the detailsview, and if I click on a paging link (2) the gridview will then load. I want the gridview to load automatically with the very first record without having to click on the pager of the details view. How do I tell the gridview to load based on the first record from the details view control without clicking on the paging link?I tested your code and found that the reason why Gridview does not load is because there is no value in userid.
So please make sure there is a value in userid.
Best regards,
Sam
Monday, June 1, 2020 4:23 AM -
User-1767698477 posted
At the moment, upon login, the gridview is not loading any rows. The details view displays record 1 which is Test company and there is one paging link for record #2. The details view displays the correct guid for Test company (503841a3-c615-4e4d-8cf5-20fbddbf7a7f) When you click a paging link in the details view, the gridview should load the rows for the guid which is displayed. I made this label control visible so you can so the guid. Rather than paste images here, you can login to see this live at my site. It you go to mortgageloanapply.com and login as janedoe with the password (case sensitive) Janedoe1* you will see that the details view and the label display Test Company. The gridview should be loading with 3 rows though. If you click on the 2 in the paging of the details view, the gridview will load with the wrong company. There are only 2 companies right now. 1 and 2. Clicking the 2 should bring up JD Company and display 11 rows. It displays instead the 3 rows of Test Company. So they are reversed! 1 shows 2 and 2 shows 1. Each time you click a details view page, the sql query should be based on the OriginatorID in the detailsview and the gridview should bind on this. The gridview is loading the items that agree with the label above it, but the details view is showing the other company. Can you help?
Dim UserProfileTableAdapter As New DataSet1TableAdapters.UserProfilesTableAdapter Dim UserProfile As DataSet1.UserProfilesDataTable If Not IsPostBack Then If Session("Username") = Nothing Then lblName.Text = "You have been logged out <br>due to inactivity - Please login again" Exit Sub End If lblName.Text = Session("Firstname") & " " & Session("Lastname") UserProfile = UserProfileTableAdapter.GetLOsbyprocessorID(Session("UserID")) For Each userprofilerow As DataSet1.UserProfilesRow In UserProfile Session("OriginatorID") = userprofilerow.UserID Session("Folder") = userprofilerow.Folder Label2.Text = "Applications for " & userprofilerow.Firstname & " " & userprofilerow.Lastname & " at " & userprofilerow.Company 'DetailsView1.DataBind() GridView2.DataBind() Exit For 'just get the first record Next 'Session("Folder") = UserProfileTableAdapter.GetOriginatorFolder(Session("OriginatorID")) 'where processorID-UserID will get all the row in userprofiles where a LO has the processor assigned. 'then just grab the first record and exit the next End If 'Clear these when returing to the grid Session("OriginatorID") = "" Session("docpath") = "" Session("Borfirst") = "" Session("Borlast") = "" End Sub Protected Sub DetailsView1_ItemCommand(sender As Object, e As CommandEventArgs) Dim lbl As Label = DirectCast(DetailsView1.FindControl("Label1"), Label) Dim originatorguid As Guid originatorguid = Guid.Parse(lbl.Text) Session("OriginatorID") = originatorguid Dim UserProfileTableAdapter As New DataSet1TableAdapters.UserProfilesTableAdapter Dim UserProfile As DataSet1.UserProfilesDataTable UserProfile = UserProfileTableAdapter.GetData(Session("OriginatorID")) For Each userprofilerow As DataSet1.UserProfilesRow In UserProfile Label2.Text = "Applications for " & userprofilerow.Firstname & " " & userprofilerow.Lastname & " at " & userprofilerow.Company Next Session("Folder") = UserProfileTableAdapter.GetOriginatorFolder(originatorguid) GridView2.DataBind() 'DetailsView1.DataBind() End Sub
<%@ Page Title="" Language="VB" MasterPageFile="~/templates/default1.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="users_Default" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> <title>Member Home Page</title> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <div id="menu" class="container"> </div> </asp:Content> <asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="Server"> <br /> <table align="center" width="95%"> <tr> <td align="left"> Welcome : <b> <asp:Label ID="lblName" runat="server" Text="" ForeColor="#FFB30F"></asp:Label></b> </td> <td> </td> <td align="right"> <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="change_password.aspx">Change Password</asp:HyperLink> </td> </tr> <tr> <td align="left"> <asp:LoginView ID="LoginView1" runat="server"> <LoggedInTemplate> Logged in as : <asp:LoginName ID="LoginName1" runat="server" Font-Bold="True" /> </LoggedInTemplate> <AnonymousTemplate> Your are not logged in. <br /> Click the login link to sign in. </AnonymousTemplate> </asp:LoginView> </td> <td> </td> <td align="right"> <asp:HyperLink ID="HyperLink4" runat="server" NavigateUrl="edit_profile.aspx">Edit Profile</asp:HyperLink> </td> </tr> <tr> <td align="left"> <asp:LoginStatus ID="LoginStatus1" runat="server" LogoutAction="Redirect" LogoutPageUrl="~/Logout.aspx" /> </td> <td align="center"> <h2> Loan Applications </h2> </td> <td align="right"> </td> </tr> </table> <br /> <br /> <br /> <asp:Label ID="Label2" runat="server" Text=""></asp:Label> <center> <br /> <asp:GridView ID="GridView2" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource2" OnRowDataBound="Gridview2_rowdatabound" OnRowCommand="Gridview2_Rowcommand" OnPageIndexChanging="GridView2_PageIndexChanging" CellPadding="3" ForeColor="Black" GridLines="Vertical" Width="95%" RowStyle-HorizontalAlign="Center" PagerStyle-HorizontalAlign="NotSet" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px"> <AlternatingRowStyle BackColor="#CCCCCC" /> <Columns> <asp:BoundField DataField="borfirst" HeaderText="First" SortExpression="borfirst" /> <asp:BoundField DataField="borlast" HeaderText="Last" SortExpression="borlast" /> <asp:BoundField DataField="borssn" HeaderText="SSN" SortExpression="borssnt" /> <asp:BoundField DataField="appcomplete" HeaderText="App Date" SortExpression="appcomplete" /> <asp:TemplateField ShowHeader="False" HeaderText="Create File"> <ItemTemplate> <asp:Button runat="server" Text="Create DU file" ID="CreateDUfile" CommandName="CreateDUfile" CommandArgument='<%#Bind("applicantid") %>'></asp:Button> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="3.2 File"> <ItemTemplate> <asp:Label ID="LblDUfilecreationdate" runat="server" Text=""></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField ShowHeader="False" HeaderText="Revise"> <ItemTemplate> <asp:Button ID="EditApp" Text="App" runat="server" OnCommand="Editcommand" CommandName="Editapp" CommandArgument='<%#Bind("applicantid") %>'></asp:Button> </ItemTemplate> </asp:TemplateField> <asp:TemplateField ShowHeader="False" HeaderText="Upload"> <ItemTemplate> <asp:Button ID="Upload" Text="Docs" runat="server" OnCommand="Uploadcommand" CommandName="Upload" CommandArgument='<%#Bind("applicantid") %>'></asp:Button> </ItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#CCCCCC" /> <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" /> <RowStyle /> <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" /> <SortedAscendingCellStyle BackColor="#F1F1F1" /> <SortedAscendingHeaderStyle BackColor="#808080" /> <SortedDescendingCellStyle BackColor="#CAC9C9" /> <SortedDescendingHeaderStyle BackColor="#383838" /> </asp:GridView> <br /> <asp:Label ID="Lblresult" runat="server" Text="" Visible="false" ForeColor="#0033CC"></asp:Label> </center> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:sqlConnectionString %>" SelectCommand="SELECT applicantID, userid, borfirst, borlast, borssn, appcomplete FROM loanapps WHERE (userid = @userid) AND (appcomplete <> '1900-01-01 00:00:00.000')"> <SelectParameters> <asp:SessionParameter Name="userid" SessionField="OriginatorID" /> </SelectParameters> </asp:SqlDataSource> <br /> <br /> </asp:Content> <asp:Content ID="Content4" ContentPlaceHolderID="ContentPlaceHolder3" runat="Server"> <div id="Div1" class="container"> <asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" CellSpacing="2" DataKeyNames="UserID" DataSourceID="SqlDataSource1" Height="50px" Width="300px" ForeColor="Black" OnItemCommand="DetailsView1_ItemCommand" GridLines="Horizontal" Font-Bold="True" > <EditRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" /> <Fields> <asp:BoundField DataField="Company" HeaderText="Company : " SortExpression="Company" HeaderStyle-HorizontalAlign="Right" HeaderStyle-Width="130" /> <asp:BoundField DataField="CompanyNMLS" HeaderText="Company NMLS : " SortExpression="CompanyNMLS" HeaderStyle-HorizontalAlign="Right" /> <asp:BoundField DataField="Firstname" HeaderText="First : " SortExpression="Firstname" HeaderStyle-HorizontalAlign="Right" /> <asp:BoundField DataField="Lastname" HeaderText="Last : " SortExpression="Lastname" HeaderStyle-HorizontalAlign="Right" /> <asp:BoundField DataField="Title" HeaderText="Title : " SortExpression="Title" HeaderStyle-HorizontalAlign="Right" /> <asp:BoundField DataField="NMLS" HeaderText="NMLS : " SortExpression="NMLS" HeaderStyle-HorizontalAlign="Right" /> <asp:BoundField DataField="Phone" HeaderText="Phone : " SortExpression="Phone" HeaderStyle-HorizontalAlign="Right" /> <asp:TemplateField> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Eval("UserID") %>' CommandArgument='<%# Eval("UserID") %>' Visible="true"></asp:Label> </ItemTemplate> </asp:TemplateField> </Fields> <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" /> <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" BorderStyle="Double" /> <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" /> <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" /> </asp:DetailsView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:sqlConnectionString %>" SelectCommand="SELECT UserID, Company, CompanyNMLS, Firstname, Lastname, Title, NMLS, Phone, ProcessorID, Processor, Processoremail, ProcessorDob, ProcessorInfo, Folder, Subscription, TrialStart, SubscriptionStart, SubscriptionEnd FROM UserProfiles WHERE (ProcessorID = @ProcessorID)"> <SelectParameters> <asp:SessionParameter Name="ProcessorID" SessionField="UserID" Type="Object" /> </SelectParameters> </asp:SqlDataSource> </div> </asp:Content>
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, June 3, 2020 6:23 AM -
User-943250815 posted
To me you are very close, but suffering with "who comes first", so you problem is right on page load, not after, because DetailsView.ItemCommand "reset" the session variable used by SqlDataSource assigned to GridView.
So be sure you are storing correct value on Session variable "OriginatorID" at Page Load, right now it can have a value, but query is not returning any data to bind on Gridview, no records no gridview.
Have in mind, at DetailsView.ItemCommand you are setting Session again, but this time with a right value, thats why GridView show when you click on DetailsView.PagerFor Each userprofilerow As DataSet1.UserProfilesRow In UserProfile Session("OriginatorID") = userprofilerow.UserID ' <--- Place a breakpoint and check what value you have
Wednesday, June 3, 2020 10:02 PM -
User-1767698477 posted
I have amazingly figured this out. I was looking at datalist controls and the prerender event. This brought me to a page where the full gamut of detailsview specs are available.
I tried the pageindexchagned event and I moved a few things around. Also, I was clearing out the OriginatorID in the page load event. I deleted this and now it is loading for me properly at login time. The details view is also in sync.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then If Session("Username") = Nothing Then lblName.Text = "You have been logged out <br>due to inactivity - Please login again" Exit Sub End If lblName.Text = Session("Firstname") & " " & Session("Lastname") Dim UserProfileTableAdapter As New DataSet1TableAdapters.UserProfilesTableAdapter Dim UserProfile As DataSet1.UserProfilesDataTable UserProfile = UserProfileTableAdapter.GetLOsbyprocessorID(Session("UserID")) For Each userprofilerow As DataSet1.UserProfilesRow In UserProfile Label2.Text = "Applications for " & userprofilerow.Firstname & " " & userprofilerow.Lastname & " at " & userprofilerow.Company Session("OriginatorID") = userprofilerow.UserID Session("Folder") = userprofilerow.Folder Dim a As Guid = Session("UserID") Exit For 'just get the first record Next 'Session("Folder") = UserProfileTableAdapter.GetOriginatorFolder(Session("OriginatorID")) 'where processorID-UserID will get all the row in userprofiles where a LO has the processor assigned. 'then just grab the first record and exit the next GridView2.DataBind() End If 'Clear these when returing to the grid Session("docpath") = "" Session("Borfirst") = "" Session("Borlast") = "" End Sub Protected Sub DetailsView1_PageIndexChanged(ByVal sender As Object, ByVal e As EventArgs) DetailsView1.DataBind() Dim lbl As Label = DirectCast(DetailsView1.FindControl("Label1"), Label) Dim originatorguid As Guid originatorguid = Guid.Parse(lbl.Text) Session("OriginatorID") = originatorguid Dim UserProfileTableAdapter As New DataSet1TableAdapters.UserProfilesTableAdapter Dim UserProfile As DataSet1.UserProfilesDataTable UserProfile = UserProfileTableAdapter.GetData(Session("OriginatorID")) For Each userprofilerow As DataSet1.UserProfilesRow In UserProfile Label2.Text = "Applications for " & userprofilerow.Firstname & " " & userprofilerow.Lastname & " at " & userprofilerow.Company Next Session("Folder") = UserProfileTableAdapter.GetOriginatorFolder(originatorguid) GridView2.DataBind() End Sub
Saturday, June 6, 2020 1:10 AM