gpt4 book ai didi

asp.net - 在 WebPart 编辑器区域中添加自定义属性

转载 作者:行者123 更新时间:2023-12-02 16:06:38 24 4
gpt4 key购买 nike

  • 我有显示内容的网页部件。
  • 使用 Webpart Editor 区域,我需要选择显示样式。
  • 通过选择样式,我需要将数据显示在网格、列表或滚动(来自下拉列表)中。
  • 如何在 Web 部件编辑器区域中添加自定义属性。

我是这方面的新手。

我用 Google 搜索过此事,但一无所获。

感谢任何帮助。

最佳答案

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.

喜欢

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

关于asp.net - 在 WebPart 编辑器区域中添加自定义属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22654794/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com