2014-03-26 37 views
3
  • 我有顯示內容的web部件。
  • 使用Web部件編輯器區域我需要選擇顯示樣式。
  • 通過選擇樣式我需要數據顯示在網格或列表或滾動(從下拉列表中)。
  • 如何在Web部件編輯器區域中添加自定義屬性。

我是新手。在WebPart編輯器中添加定製屬性區域

我已經谷歌關於這個,但沒有得到。

任何幫助被讚賞。

回答

5

由於Mathew Collins writes

我沒有得到任何答覆這裏,但我卻能辦法找出該 做一些這些。

  1. 最後我決定修改EditorPart類。

  2. ApplyChanges()和SyncChanges()方法實質上只是將頁面上的更改持久化到個性化blob,反之亦然。這是在頁面上渲染一些控件的問題,並且這些方法將值映射到Web部件的屬性。

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 
相關問題