Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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):

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...