我的用户自定义服务器控件来控制DataGrid的外观,部分代码如下:
Public Class GridStyle
Inherits System.Web.UI.WebControl
Implements INamingContainer
<Category("设置"), DefaultValue(""), Description("绑定到要操作的DataGrid上")> Property BindDataGrid() As DataGrid
Get
If ViewState("_DataGridID") Is Nothing Then
Return Nothing
Else
Return Page.FindControl(ViewState("_DataGridID"))
End If
End Get
Set(ByVal Value As DataGrid)
DataGridID = Value.ID
End Set
End Property
<Category("设置"), Description("绑定到要操作的DataGrid的ID")> Property DataGridID() As String
Get
If ViewState("_DataGridID") Is Nothing Then
Return String.Empty
Else
Return ViewState("_DataGridID")
End If
End Get
Set(ByVal Value As String)
ViewState("_DataGridID") = Value
End Set
End Property
……
End Class
在设计器中编辑了BindDataGrid属性后,我碰到如下两个问题:
<1>在属性栏中DataGridID点击一下也会随之改变,但切换到HTML后DataGrid属性并未改变.
<2>HTM中没有BindDataGrid属性的值得记录,也就是说我关闭编辑页面在打开后,属性值丢失。
请教各位大侠我该如何做,谢谢。
Public Class GridStyle
Inherits System.Web.UI.WebControl
Implements INamingContainer
<Category("设置"), DefaultValue(""), Description("绑定到要操作的DataGrid上")> Property BindDataGrid() As DataGrid
Get
If ViewState("_DataGridID") Is Nothing Then
Return Nothing
Else
Return Page.FindControl(ViewState("_DataGridID"))
End If
End Get
Set(ByVal Value As DataGrid)
DataGridID = Value.ID
End Set
End Property
<Category("设置"), Description("绑定到要操作的DataGrid的ID")> Property DataGridID() As String
Get
If ViewState("_DataGridID") Is Nothing Then
Return String.Empty
Else
Return ViewState("_DataGridID")
End If
End Get
Set(ByVal Value As String)
ViewState("_DataGridID") = Value
End Set
End Property
……
End Class
在设计器中编辑了BindDataGrid属性后,我碰到如下两个问题:
<1>在属性栏中DataGridID点击一下也会随之改变,但切换到HTML后DataGrid属性并未改变.
<2>HTM中没有BindDataGrid属性的值得记录,也就是说我关闭编辑页面在打开后,属性值丢失。
请教各位大侠我该如何做,谢谢。
PersistenceMode(PersistenceMode.Attribute)如: [
Category("样式"),
Description(""),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
PersistenceMode(PersistenceMode.Attribute)
]
public TableItemStyle AlternatingItemStyle
{
get
{
if(_altItemStyle == null)
{
_altItemStyle = new TableItemStyle();
if(IsTrackingViewState)
{
((IStateManager)_altItemStyle).TrackViewState();
}
}
return _altItemStyle;
}
}