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
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
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
How do I tell the gridview to load based on the first record from the details view control without clicking on the paging link?
sking
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
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
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 Gridview
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
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
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
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.Pager
sking
For Each userprofilerow As DataSet1.UserProfilesRow In UserProfile
Session("OriginatorID") = userprofilerow.UserID ' <--- Place a breakpoint and check what value you have
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
Member
247 Points
1310 Posts
Gridview not loading on page load
May 25, 2020 02:37 AM|sking|LINK
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?
California Mortgage | California refinance
Contributor
3370 Points
1409 Posts
Re: Gridview not loading on page load
May 26, 2020 01:58 AM|samwu|LINK
Hi sking,
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
Member
247 Points
1310 Posts
Re: Gridview not loading on page load
May 27, 2020 07:11 AM|sking|LINK
California Mortgage | California refinance
Contributor
3370 Points
1409 Posts
Re: Gridview not loading on page load
May 28, 2020 03:19 AM|samwu|LINK
Hi sking,
In your aspx page, I didn't find DetailsView, please post the complete aspx code.
Best regards,
Sam
Member
247 Points
1310 Posts
Re: Gridview not loading on page load
May 30, 2020 04:31 AM|sking|LINK
Sorry, here is the code:
California Mortgage | California refinance
Participant
1061 Points
665 Posts
Re: Gridview not loading on page load
May 30, 2020 05:01 PM|jzero|LINK
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 Gridview
Contributor
3370 Points
1409 Posts
Re: Gridview not loading on page load
Jun 01, 2020 04:23 AM|samwu|LINK
Hi sking,
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
Member
247 Points
1310 Posts
Re: Gridview not loading on page load
Jun 03, 2020 06:23 AM|sking|LINK
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?
California Mortgage | California refinance
Participant
1061 Points
665 Posts
Re: Gridview not loading on page load
Jun 03, 2020 10:02 PM|jzero|LINK
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.Pager
Member
247 Points
1310 Posts
Re: Gridview not loading on page load
Jun 06, 2020 01:10 AM|sking|LINK
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.
https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.detailsview.-ctor?view=netframework-4.8
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.
California Mortgage | California refinance