|
-
Nov 25th, 2011, 11:22 PM
#1
Thread Starter
Frenzied Member
Details View Paging
I am trying to implement paging in my detials view which is bound to a data table created at run time from a .txt file the user uploads
when i run the program and click page 2 this is the error i have gotten
'DetailsView1' fired event PageIndexChanging which wasn't handled
I cant seem to determine how to correctly implement this. From what i am reading I thought I could just bind the Details View to the table, which is what i do in my code-behind since it created at run time
-
Nov 25th, 2011, 11:50 PM
#2
Re: Details View Paging
This Should help you out..
__________________
Rate the posts that helped you 
-
Nov 26th, 2011, 01:05 AM
#3
Thread Starter
Frenzied Member
Re: Details View Paging
Thanks that helped a bit
Another problem Ihave is that, I create the table with the fileupload
Code:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles UpLoadFile_btn.Click
FileName.InnerHtml = FileUpload1.PostedFile.FileName
FileContent.InnerHtml = FileUpload1.PostedFile.ContentType
FileSize.InnerHtml = FileUpload1.PostedFile.ContentLength
UploadDetails.Visible = True
Dim strFileName As String = FileUpload1.PostedFile.FileName
Dim c As String = System.IO.Path.GetFileName(strFileName) ' We don't need the path, just the name.
Try
FileUpload1.PostedFile.SaveAs("C:\UploadedUserFiles\" + c)
Span1.InnerHtml = "File Uploaded Sucessfully."
Catch Exp As Exception
Span1.InnerHtml = "Some Error occured."
UploadDetails.Visible = False
End Try
Using myReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(strFileName)
myReader.SetDelimiters(vbTab)
Dim currentRow As String()
currentRow = myReader.ReadFields()
Dim colNameList As New List(Of String)
Dim colName As String = String.Empty
For i As Integer = 0 To currentRow.GetUpperBound(0)
colName = currentRow(i)
Dim suffix As Integer = 1
While colNameList.Contains(colName)
colName = currentRow(i) & suffix.ToString
suffix += 1
End While
colNameList.Add(colName)
Next
For Each currentField As String In colNameList
table.Columns.Add(currentField, GetType(System.String))
Next
While Not myReader.EndOfData
Try
currentRow = myReader.ReadFields()
table.Rows.Add(currentRow)
Catch ex As Exception
End Try
End While
End Using
If Table.Columns.Contains("Column1") Then
Table.Columns.Remove("Column1")
End If
dtAll = table
Me.DetailsView1.AutoGenerateRows = True
Me.DetailsView1.DataSource = table
Me.DetailsView1.DataBind()
So I think on the pageindexchange i need to re-bind?
I am a bit lost here in ASP land
-
Nov 27th, 2011, 11:11 PM
#4
Re: Details View Paging
 Originally Posted by billboy
So I think on the pageindexchange i need to re-bind?
I am a bit lost here in ASP land
yes, In Gridview's PageIndexChanging you need to first set the PageIndex property of gridview to e.NewPageIndex and rebind the gridview with underlying datasource
PS:Make sure the gridview's AllowPaging is set to True
__________________
Rate the posts that helped you 
-
Nov 28th, 2011, 03:46 PM
#5
Thread Starter
Frenzied Member
Re: Details View Paging
I am using DetailsView, so I need to set the page index to e.newpageindex in the pageindexchanging event and rebind to my datatable?
-
Nov 30th, 2011, 10:53 PM
#6
Thread Starter
Frenzied Member
Re: Details View Paging
Can somesome show me where i am going wrong??
Code:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles UpLoadFile_btn.Click
FileName.InnerHtml = FileUpload1.PostedFile.FileName
FileContent.InnerHtml = FileUpload1.PostedFile.ContentType
FileSize.InnerHtml = FileUpload1.PostedFile.ContentLength
UploadDetails.Visible = True
Dim strFileName As String = FileUpload1.PostedFile.FileName
Dim c As String = System.IO.Path.GetFileName(strFileName)
Try
FileUpload1.PostedFile.SaveAs("C:\UploadedUserFiles\" + c)
Span1.InnerHtml = "File Uploaded Sucessfully."
Catch Exp As Exception
Span1.InnerHtml = "Some Error occured."
UploadDetails.Visible = False
End Try
CreateTable(FileName.InnerHtml)
binddetailsviewdata(table)
End Sub
Private Sub binddetailsviewdata(ByVal table As DataTable)
Me.DetailsView1.DataSource = table
Me.DetailsView1.DataBind()
End Sub
Protected Sub DetailsView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewPageEventArgs) Handles DetailsView1.PageIndexChanging
Me.DetailsView1.PageIndex = e.NewPageIndex
binddetailsviewdata(table)
End Sub
Private Function CreateTable(ByVal filepath As String) As DataTable
Using myReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(FileName.InnerHtml)
myReader.SetDelimiters(vbTab)
Dim currentRow As String()
currentRow = myReader.ReadFields()
Dim colNameList As New List(Of String)
Dim colName As String = String.Empty
For i As Integer = 0 To currentRow.GetUpperBound(0)
colName = currentRow(i)
Dim suffix As Integer = 1
While colNameList.Contains(colName)
colName = currentRow(i) & suffix.ToString
suffix += 1
End While
colNameList.Add(colName)
Next
For Each currentField As String In colNameList
table.Columns.Add(currentField, GetType(System.String))
Next
While Not myReader.EndOfData
Try
currentRow = myReader.ReadFields()
table.Rows.Add(currentRow)
Catch ex As Exception
End Try
End While
End Using
If table.Columns.Contains("Column1") Then
table.Columns.Remove("Column1")
End If
Return table
End Function
-
Dec 2nd, 2011, 01:17 AM
#7
Re: Details View Paging
in below code how do you get the value for table is it being recreated on pageload? if not than you have to recreate object before binding it with DetailsView1?
vb Code:
Protected Sub DetailsView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewPageEventArgs) Handles DetailsView1.PageIndexChanging
Me.DetailsView1.PageIndex = e.NewPageIndex
binddetailsviewdata(table)
End Sub
__________________
Rate the posts that helped you 
-
Dec 2nd, 2011, 12:08 PM
#8
Thread Starter
Frenzied Member
Re: Details View Paging
I simplified my code a bit, but its basically the same and still having the same problem.
I thought I needed to recreate the table, however when I do that and page I get error that a column in that table already exisits?? So it seems the table is still there. If I reload my file then my details view displays at the selected page. So it must be where the table is being recreated
Code:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles UpLoadFile_btn.Click
FileName.InnerHtml = FileUpload1.PostedFile.FileName
FileContent.InnerHtml = FileUpload1.PostedFile.ContentType
FileSize.InnerHtml = FileUpload1.PostedFile.ContentLength
UploadDetails.Visible = True
Dim strFileName As String = FileUpload1.PostedFile.FileName
Dim c As String = System.IO.Path.GetFileName(strFileName)
Try
FileUpload1.PostedFile.SaveAs("C:\UploadedUserFiles\" + c)
Span1.InnerHtml = "File Uploaded Sucessfully."
Catch Exp As Exception
Span1.InnerHtml = "Some Error occured."
UploadDetails.Visible = False
End Try
BindDetailsView()
End Sub
Protected Sub BindDetailsView()
CreateTable()
Me.DetailsView1.DataSource = table
Me.DetailsView1.DataBind()
TextBox1.Text = table.Rows.Count.ToString
End Sub
Protected Sub DetailsView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewPageEventArgs) Handles DetailsView1.PageIndexChanging
Me.DetailsView1.PageIndex = e.NewPageIndex
BindDetailsView()
End Sub
Private Function CreateTable() As DataTable
Using myReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(FileName.InnerHtml)
myReader.SetDelimiters(vbTab)
Dim currentRow As String()
currentRow = myReader.ReadFields()
Dim colNameList As New List(Of String)
Dim colName As String = String.Empty
For i As Integer = 0 To currentRow.GetUpperBound(0)
colName = currentRow(i)
Dim suffix As Integer = 1
While colNameList.Contains(colName)
colName = currentRow(i) & suffix.ToString
suffix += 1
End While
colNameList.Add(colName)
Next
For Each currentField As String In colNameList
table.Columns.Add(currentField, GetType(System.String))
Next
While Not myReader.EndOfData
Try
currentRow = myReader.ReadFields()
table.Rows.Add(currentRow)
Catch ex As Exception
End Try
End While
End Using
If table.Columns.Contains("Column1") Then
table.Columns.Remove("Column1")
End If
Return table
End Function
Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
Dim UpPath As String
Dim UpName As String
UpPath = "C:\UploadedUserFiles2008"
UpName = Dir(UpPath, vbDirectory)
If UpName = "" Then
MkDir("C:\UploadedUserFiles2008\")
End If
End Sub
-
Dec 5th, 2011, 02:39 AM
#9
Re: Details View Paging
Hello,
It is not clear from your above code, but where exactly are you storing the table? Or are you actually happy to be recreating it from scratch each time?
On each PostBack to the server, are you actually calling CreateTable()? If so, I am surprised that FileName.InnerHtml actually still contains a value. What sort of control is FileName?
Gary
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|