3
  • I have webparts which display the content.
  • Using Webpart Editor zone I need to select display style.
  • By Selecting the Style i need the data to be displayed either in Grid or List or Rolling (from Dropdownlist).
  • How can i add custom property in Webpart Editor Zone.

I'm newbie to this.

I have Google'd about this but got nothing.

Any help is Appreciated.

Amarnath Balasubramanian
  • 9,300
  • 8
  • 34
  • 62

1 Answers1

5

As Mathew Collins writes:

I didn't get any replies here, but I was able to figure out a way to do some of these.

  1. In the end I decided to overirde the EditorPart class.

  2. The ApplyChanges() and SyncChanges() methods essentially just persist the changes from the page to the personalization blob and vice-versa. It's a matter of rendering some controls on the page, and mapping the values to the properties of the web part in these methods.

Like

Imports Microsoft.VisualBasic
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Data
Imports FormsUtilities

Namespace CustomEditorZone

    Public Class CustomEditor : Inherits EditorPart

        Public Sub New()
            Me.Title = "Change Display Style"
        End Sub 'New

        Private PartPropertyValue As DropDownList

        Protected Overrides Sub CreateChildControls()
            Controls.Clear()
            PartPropertyValue = New DropDownList()
            PartPropertyValue.AppendDataBoundItems = True
            PartPropertyValue.Items.Add("")
            PopulateControl(PartPropertyValue)
            Me.Controls.Add(PartPropertyValue)
        End Sub 'CreateChildControls

        Public Overrides Function ApplyChanges() As Boolean

            EnsureChildControls()
            Dim MyWebPart As GenericWebPart = DirectCast(WebPartToEdit, GenericWebPart)
            Dim MyControl As CustomWebPart.WebPartBaseConsumer = DirectCast(MyWebPart.ChildControl, CustomWebPart.WebPartBaseConsumer)
            MyControl.DisplayStyle = PartPropertyValue.SelectedItem.Text
            Return True

        End Function 'ApplyChanges

        Public Overrides Sub SyncChanges()
            Try
                EnsureChildControls()
                Dim MyWebPart As GenericWebPart = DirectCast(WebPartToEdit, GenericWebPart)
                Dim MyControl As CustomWebPart.WebPartBaseConsumer = DirectCast(MyWebPart.ChildControl, CustomWebPart.WebPartBaseConsumer)
                Dim CurrentDisplay As String = MyControl.DisplayStyle

                For Each Item As ListItem In PartPropertyValue.Items
                    If Item.Text = CurrentDisplay Then
                        Item.Selected = True
                        Exit For
                    End If
                Next
            Catch ex As Exception

            End Try

        End Sub 'SyncChanges

        Protected Overrides Sub RenderContents(ByVal writer As HtmlTextWriter)
            Try
                writer.Write("Display Style :")
                writer.Write(" ")
                Me.PartPropertyValue.RenderControl(writer)
            Catch ex As Exception

            End Try

        End Sub 'RenderContents

        Private Sub PopulateControl(ByRef PartPropertyValue As DropDownList)

            PartPropertyValue.Items.Add("Grid")
            PartPropertyValue.Items.Add("List")
            PartPropertyValue.Items.Add("Rolling")
        End Sub

    End Class 'CustomEditor
End Namespace
Community
  • 1
  • 1
Vignesh Kumar A
  • 27,863
  • 13
  • 63
  • 115