在WebPart编辑器区域中添加自定义属性

时间:2014-03-26 08:02:57

标签: asp.net vb.net web-parts editor-zone

  • 我有显示内容的webparts。
  • 使用Webpart Editor区域我需要选择显示样式。
  • 通过选择样式我需要在网格或列表或滚动(从下拉列表)中显示数据。
  • 如何在Webpart Editor Zone中添加自定义属性。

我是新手。

我有谷歌关于这个但没有得到任何东西。

任何帮助都是赞赏的。

1 个答案:

答案 0 :(得分:5)

作为Mathew Collins writes

  

我在这里没有得到任何回复,但我能够想出办法   做其中一些。

     
      
  1. 最后我决定覆盖EditorPart类。

  2.   
  3. ApplyChanges()和SyncChanges()方法基本上只是将更改从页面持久保存到个性化blob和   反之亦然。这是在页面上呈现一些控件的问题,并且   在这些方法中将值映射到Web部件的属性。

  4.   

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