Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET Website Programming Problem-Design-Solution
This is the forum to discuss the Wrox book ASP.NET Website Programming: Problem - Design - Solution, Visual Basic .NET Edition by Marco Bellinaso, Kevin Hoffman; ISBN: 9780764543869
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET Website Programming Problem-Design-Solution section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 12th, 2003, 06:49 PM
Authorized User
 
Join Date: Jun 2003
Location: New orleans, Louisiana, USA.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default Forum DataGrid help

I'm trying to get the reply author's info from codebehind I can already get the topic author's info. Example in red and green for clarity.


Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls

Imports Wrox.WebModules.Accounts.Business

Namespace WebModules.Forums.Web

  Public Class Topic
    Inherits Wrox.ThePhile.Web.PhilePage


    ' Private Variable
    '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    Private myCanModerateForums As Boolean



    ' Page Controls
    '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    Protected Header As Web.Controls.User.Header

    Protected RepliesGrid As DataGrid
    Protected PageNumber As Label
    Protected TotalPages As Label
    Protected FirstPage As LinkButton
    Protected PreviousPage As LinkButton
    Protected NextPage As LinkButton
    Protected LastPage As LinkButton
    Protected DeleteTopic As LinkButton
    Protected EditTopic As HyperLink
    Protected TopicTable As HtmlTable
    Protected TopicAuthor As Label
    Protected TopicSubject As Label
    Protected TopicMessage As Label
    Protected TopicAuthorSignature As Label
    Protected TopicAuthorAvatar As WebControls.Image
    Protected TopicAuthorHomepage As HyperLink
    Protected TopicDate As Label
    Protected TopicTime As Label
    Protected GridItemStyle As Label
    Protected GridAlternatingItemStyle As Label
    Protected NewTopic As HyperLink
    Protected NewReply As HyperLink




    ' Page Events
    '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    Protected Overrides Sub OnInit(ByVal e As EventArgs)
      MyBase.OnInit(e)
      InitializeComponent()
    End Sub


    ' This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
      AddHandler Me.Load, AddressOf Page_Load
    End Sub


    Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

      ' Check if the user has the permission to moderate the forums
      myCanModerateForums = Context.User.Identity.IsAuthenticated _
        AndAlso CType(Context.User, SitePrincipal).HasPermission( _
          CInt(ForumsPermissions.ModerateForums))

      Dim topicId As String = "-1"

      ' Get the ForumId from the QueryString
      If Not (Request.QueryString("TopicId") Is Nothing) Then
        topicId = Request.Params("TopicId")
      End If

      ' Show or hide the Edit and Delete topic links, according
      ' to the permissions of the current user
      EditTopic.NavigateUrl = "PostMessage.aspx?Action=EditTopic&TopicId=" _
        & topicId.ToString()
      EditTopic.Visible = myCanModerateForums
      DeleteTopic.Visible = myCanModerateForums

      If Not Page.IsPostBack Then

        Dim topic As Business.Topic

        ' If the TopicKey value is not null, find the topic with that
        ' key and redirect to it
        If Not (Request.QueryString("TopicKey") Is Nothing) Then

          topic = New Business.Topic( _
            Request.QueryString("TopicKey").ToString())

          ' If found, redirect to it, otherwise redirect to Default.aspx
          If topic.Id <> -1 Then
            Response.Redirect( _
              "Topic.aspx?TopicId=" & topic.Id.ToString(), True)
          Else
            Response.Redirect("Default.aspx", True)
          End If

          ' Otherwise it means that we have a TopicId to use directly
        Else


          ' Set the links for posting a new topic/reply
          topic = New Business.Topic(Integer.Parse(topicId))
          NewTopic.NavigateUrl &= topic.Forum.Id.ToString()
          NewReply.NavigateUrl &= topic.Id.ToString()

          ' Set the navigation bar TopicId
          Header.TopicId = Integer.Parse(topicId)

          ' If there is the paramter idicating to show the last page, set
          ' the(number) in the label. This will be read in the BindGrid
          ' procedure

          If Not (Request.QueryString("Display") Is Nothing) _
            AndAlso Request.QueryString("Display").ToString().ToLower( ) _
              = "lastpage" Then

            Dim pageSize As Integer = _
              Configuration.ModuleConfig.GetSettings().RepliesPe rPage
            Dim totalPages As Integer = CInt(Math.Ceiling(( _
              System.Convert.ToDouble(topic.Replies) / pageSize)))
            PageNumber.Text = totalPages.ToString()

          End If

          ' Bind the data to the grid
          RepliesGrid.Attributes("TopicId") = topicId
          BindGrid()

        End If

     'I can get the topic's author's info like this

                    Dim author As Business.Member = topic.Member
                    Dim authemail As String

                    authemail = CType(author.Email, String)

      End If

    ‘ how do I get the replies author’s info. Note: Its in a datagrid unlike the topic authors. Tried this: but not working. its return 0 as member id

     Dim reply As New Business.Reply(topicId)

                Dim reauthor As Business.Member = reply.Member

                Dim recurruser As String

                recurruser = CType(reply.MemberId, String)

    End Sub



    ' Control Events
    '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    Protected Sub RepliesGrid_Delete( _
      ByVal sender As Object, _
      ByVal e As DataGridCommandEventArgs)

      ' If the user cannot moderate forums redirect to the login page
      If Not myCanModerateForums Then
        Response.Redirect( _
          "/ThePhileVB/WebModules/Accounts/Login.aspx?ShowError=true", True)
      End If

      ' Delete this reply
      Dim reply As New Business.Reply( _
        CInt(RepliesGrid.DataKeys(e.Item.ItemIndex)))
      reply.Delete()

      BindGrid()

    End Sub


    Protected Sub DeleteTopic_Click( _
      ByVal sender As Object, _
        ByVal e As EventArgs)

      ' If the user cannot moderate forums redirect to the login page
      If Not myCanModerateForums Then
        Response.Redirect( _
          "/ThePhileVB/WebModules/Accounts/Login.aspx?ShowError=true", True)
      End If

      Dim topicId As Integer = Integer.Parse(Request.QueryString("TopicId"))
      Dim topic As New Business.Topic(topicId)
      Dim forumId As Integer = topic.ForumId

      topic.Delete()
      Response.Redirect(("Forum.aspx?ForumId=" + forumId.ToString()))

    End Sub


    Protected Sub RepliesGrid_PageChanged( _
      ByVal sender As Object, _
      ByVal e As CommandEventArgs)

      If PageNumber.Text.Trim().Length = 0 Then
        Return
      End If

      Select Case e.CommandName
        Case "FirstPage"
          PageNumber.Text = "1"
        Case "PreviousPage"
          PageNumber.Text = (Integer.Parse(PageNumber.Text) - 1).ToString()
        Case "NextPage"
          PageNumber.Text = (Integer.Parse(PageNumber.Text) + 1).ToString()
        Case "LastPage"
          PageNumber.Text = TotalPages.Text
      End Select

      ' Show the new page
      BindGrid()

    End Sub



    ' Methods
    '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    Public Function GetAuthorText( _
      ByVal memberName As Object, _
      ByVal eMail As Object, _
      ByVal showEmail As Object) _
      As String

      ' Return the member Name only or a link to its e-mail address,
      ' according to the ShowEmail value
      If Not Convert.ToBoolean(showEmail) Then
        Return memberName.ToString()
      Else
        Return String.Format("<a href=""mailto:{0}"">{1}</a>", _
          eMail.ToString(), memberName.ToString())
      End If

    End Function


    Public Function ProcessTags(ByVal rawText As Object) As String
      Return Business.Helper.ProcessSpecialTags(rawText.ToStrin g())
    End Function



    ' Properties
    '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    Public ReadOnly Property CanModerateForums() As Boolean
      Get
        Return myCanModerateForums
      End Get
    End Property



    ' Private Code
    '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    Protected Sub BindGrid()

      ' Get the ForumId value from the Grid's attributes.
      ' if null, redirect to the Default.aspx page
      If RepliesGrid.Attributes("TopicId") Is Nothing Then
        Response.Redirect("Default.aspx", True)
      End If

      ' Get the current forum's Id
      Dim topicId As Integer = _
        Integer.Parse(RepliesGrid.Attributes("TopicId"))

      ' Get the number of topics per page
      Dim pageSize As Integer = _
        Configuration.ModuleConfig.GetSettings().RepliesPe rPage

      ' Get the current replies page
      Dim pageNum As Integer = _
        IIf(PageNumber.Text.Trim().Length = 0, _
          1, Integer.Parse(PageNumber.Text))

      ' Retrieve and bind the records to the grid
      Dim topic As New Business.Topic(topicId)
      Dim replies As DataSet = topic.GetReplies(pageNum)
      RepliesGrid.DataSource = replies.Tables(0).DefaultView
      RepliesGrid.DataBind()

      ' Show the total number of pages
      Dim numPages As Integer = CInt(Math.Ceiling( _
        (System.Convert.ToDouble(topic.Replies) / pageSize)))


      If numPages = 0 Then
        numPages = 1
      End If
      TotalPages.Text = numPages.ToString()

      ' Enable/disable the links to navigate through the pages
      FirstPage.Enabled = pageNum <> 1
      PreviousPage.Enabled = pageNum <> 1
      NextPage.Enabled = pageNum <> numPages
      LastPage.Enabled = pageNum <> numPages

      ' Show also the topic, if this is the first page
      If pageNum = 1 Then

        BindTopicControls(topicId)
        TopicTable.Visible = True
        ' If this is the first page, also swap the styles for the Item
        ' and AlternatingItem of the DataGrid, because the Topic has
        ' the Item style
        RepliesGrid.ItemStyle.CssClass = GridAlternatingItemStyle.Text
        RepliesGrid.AlternatingItemStyle.CssClass = GridItemStyle.Text

      Else

        TopicTable.Visible = False
        RepliesGrid.ItemStyle.CssClass = GridItemStyle.Text
        RepliesGrid.AlternatingItemStyle.CssClass = _
          GridAlternatingItemStyle.Text

      End If

    End Sub


    Private Sub BindTopicControls(ByVal topicId As Integer)

      ' Retrieve all the topic's info
      Dim topic As New Business.Topic(topicId)
      Dim author As Business.Member = topic.Member

      ' Show the data
      TopicAuthor.Text = GetAuthorText( _
        author.Name, _
        author.Email, _
        author.ShowEmail)
      TopicAuthorAvatar.ImageUrl = author.AvatarUrl
      TopicAuthorAvatar.Visible = author.AvatarUrl.Length > 0
      TopicAuthorHomepage.NavigateUrl = author.Homepage
      TopicAuthorHomepage.Visible = author.Homepage.Length > 0
      TopicDate.Text = String.Format("{0:MM/dd/yy}", topic.AddedDate)
      TopicTime.Text = String.Format("{0:HH:mm:ss tt}", topic.AddedDate)
      TopicSubject.Text = topic.Subject
      TopicMessage.Text = Business.Helper.ProcessSpecialTags(topic.Message)
      TopicAuthorSignature.Text = _
        Business.Helper.ProcessSpecialTags(author.Signatur e)

    End Sub


  End Class

End Namespace

Note: Each topic can have many replies, so I would like to get the replies author's info and hold it in a string or something.

This will allow me to allow the logged on member to edit his/her topics and replies.

HELLLLP.... :)
  #2 (permalink)  
Old September 22nd, 2004, 11:13 AM
Authorized User
Points: 79, Level: 1
Points: 79, Level: 1 Points: 79, Level: 1 Points: 79, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2004
Location: , , .
Posts: 11
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to bisigreat
Default

how do i pouplate datagrid from a recordset object

  #3 (permalink)  
Old September 24th, 2004, 06:23 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Atlanta, Georgia, USA.
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts
Default

drfunkie - Your comments at the bottom don't seem like a good way to do it:

>Note: Each topic can have many replies, so I would like to get the replies
>author's info and hold it in a string or something.
>This will allow me to allow the logged on member to edit his/her topics
>and replies.

This would be very hard. The easier option is just to make the edit link visible only on messages that were originated by the current user. It would be nasty to have a collection (you wouln't use a string for this) of replies. What exactly would you do with it?

This Wrox forum does it the way I suggested - they show the edit link on messages you wrote yourself. This is handled separately on a per-messsage basis.

Eric
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom paging in Datagrid with datagrid page count madhusrp ASP.NET 1.0 and 1.1 Professional 12 June 2nd, 2008 01:15 PM
User COntrol Datagrid inside datagrid rodmcleay ASP.NET 1.0 and 1.1 Professional 3 April 14th, 2007 10:11 AM
How can I creat a forum like P2P Forum? pcassiano ASP.NET 1.0 and 1.1 Basics 1 October 31st, 2005 05:00 AM
Forum Help torch BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 2 June 12th, 2005 12:22 PM
converting Forum.aspx to Forum.ascx (help) drfunkie BOOK: ASP.NET Website Programming Problem-Design-Solution 1 July 11th, 2003 12:27 PM



All times are GMT -4. The time now is 05:58 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.