Datagrid Template or Class - Confused

lorena

Well-known member
Joined
Oct 23, 2003
Messages
134
Location
Phoenix, Arizona
I am having problems because I need to create a series of .aspx pages (VS 2003) which all have the same basic function. They will list files into a pageable sortable datagrid.
I have this working code (I am shortening some of it):
Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
				If Not Page.IsPostBack Then
					SortExpression = "Name"
					SortAscending = True
					BindGrid()
				End If
			End Sub
			
			Sub BindGrid()
				 deleted code that reads the files and writes to the grid				
				
				If SortAscending then
					dvFiles.Sort = SortExpression & " ASC" 
				Else
					dvFiles.Sort = SortExpression & " DESC" 
				End If

				dgFiles.DataSource = dvFiles
				
				dgFiles.DataBind()
				If fileCt < 51 Then
					GridPagerVisibility(False)
				Else
					GridPagerVisibility(True)
				End If
			End Sub

			Private Sub GridPagerVisibility(ByVal ShowHide As Boolean)
				dgFiles.PagerStyle.Visible = ShowHide
			End Sub
			
			Private Property SortExpression() As String
				Get
					Dim o As Object = ViewState("SortExpression")
					If o Is Nothing Then
						Return String.Empty
					Else
						Return o.ToString
					End If
				End Get

				Set(ByVal Value As String)
					ViewState("SortExpression") = Value
				End Set
			End Property

			Private Property SortAscending() As Boolean
				Get
					Dim o As Object = ViewState("SortAscending")
					If o Is Nothing Then
						Return True
					Else
						Return Convert.ToBoolean(o)
					End If
				End Get
				Set(ByVal Value As Boolean)
					ViewState("SortAscending") = Value
				End Set
			End Property
			
			Sub dgFiles_SortCommand(ByVal sender As Object, ByVal e As DataGridSortCommandEventArgs)
				If e.SortExpression = Me.SortExpression Then
					SortAscending = Not SortAscending
				Else
					SortAscending = True
				End If

				Me.SortExpression = e.SortExpression
				label1.text = SortExpression & "," & SortAscending.ToString
				BindGrid()
			End Sub
			
			Sub dgFiles_Paging(ByVal s As Object, ByVal e As DataGridPageChangedEventArgs)
				dgFiles.CurrentPageIndex = e.NewPageIndex
				BindGrid()
			End Sub
All of the pages (and there will be many many of them) will have this code. Is there any other way to re-use it other than cutting and pasting from one .aspx page to the next?
Needless to say, I have not done much with re-using code to date
Thanks for any help
 
Back
Top