CType(C, CheckBox).Checked = True
感觉不对,试试这样
((CheckBox)C).Checked = True
感觉不对,试试这样
((CheckBox)C).Checked = True
解决方案 »
- 64位win7如何安装TFS2005,提示不兼容
- 不显示删除回复显示所有回复显示星级回复显示得分回复 让SQL SERVER2005数据库,每天自动建表?不写程序。
- 为何vs2005下新建网站默认都是虚拟路径?有改变的方法没?
- 继续 ASP的一个投票系统
- 哪位给一个.net 2005的下载地址?
- 如何删除DataTable中的列或是DataGrid中自动绑定的列??
- web自定义控件,在设计时更改控件属性时HTML源代码无变化问题如何解决?
- 窗体的身份验证Web.config 中配置设置验证过期的问题?
- 使用控件连数据库时出现的问题,帮忙给看看!
- 关于将数据导入EXCEL文件的问题
- ASP.NET 页面中SQL Server2000 的数据库连接问题
- 请问一下,在asp.net中用什么方法可以改变字体~!~!~!!
elliot(!逸轩)
這樣也不行!
也没什么特别好的办法!
Overrides Protected Sub LoadViewState( _
ByVal savedState As Object _
)
[C#]
protected override void LoadViewState(
object savedState
);
[C++]
protected: void LoadViewState(
Object* savedState
);
[JScript]
protected override function LoadViewState(
savedState : Object
);
参数
savedState
表示要还原的用户控件状态的 Object。
备注
一般情况下,无需调用此方法。不过,如果在视图状态中存储自定义信息,可以重写此方法以实现此目的。例如,可以将视图状态值加载到字段中,这样将来就不必从 Control.ViewState 属性检索它。还可以在即将调用 base.SaveViewState 前将该值插入 ViewState 属性,这对于在与服务器的往返行程间保持字段是一个有效的方法。示例
[Visual Basic, C#] 下面的示例说明使用 LoadViewState 和 SaveViewState 方法管理其视图状态的用户控件。[Visual Basic] Public ReadOnly Property UserText() As String
Get
Return CStr(ViewState("usertext"))
End Get
End PropertyPublic ReadOnly Property PasswordText() As String
Get
Return CStr(ViewState("passwordtext"))
End Get
End Property
Protected Overrides Sub LoadViewState(savedState As Object)
If Not (savedState Is Nothing) Then
MyBase.LoadViewState(savedState)
End If
End Sub
Protected Overrides Function SaveViewState() As Object
ViewState("usertext") = user.Text
ViewState("passwordtext") = password.Text
Return MyBase.SaveViewState()
End Function
End Class
[C#]
public string UserText
{
get
{
return (string)ViewState["usertext"];
}
}
public string PasswordText
{
get
{
return (string)ViewState["passwordtext"];
}
}protected override void LoadViewState(object savedState)
{
if (savedState != null)
base.LoadViewState(savedState);
}protected override object SaveViewState()
{
ViewState["usertext"] = user.Text;
ViewState["passwordtext"] = password.Text;
return base.SaveViewState();
}
Adding Columns DynamicallyYou can hide and show columns if you know in advance what columns you need. Sometimes, however, you do not know that until run time. In that case, you can create columns dynamically and add them to the grid.To do so, you create an instance of one of the column classes supported by the grid — BoundColumn, EditCommandColumn, ButtonColumn, or HyperlinkColumn. (You can add template columns to the grid, but it is slightly more complex. For details, see Creating Web Server Control Templates Programmatically.) Set the column's properties, and then add it to the grid's Columns collection.The following example shows how to add two bound columns to a grid.' Visual Basic
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
'Set data-binding properties of the grid
DataGrid1.AutoGenerateColumns = False
DataGrid1.DataSource = Me.dsBooks1
DataGrid1.DataMember = "Books"
DataGrid1.DataKeyField = "bookid" ' Add two columns
Dim dgc_id As New BoundColumn()
dgc_id.DataField = "bookid"
dgc_id.HeaderText = "ID"
dgc_id.ItemStyle.Width = New Unit(80)
DataGrid1.Columns.Add(dgc_id) Dim dgc_title As New BoundColumn()
dgc_title.DataField = "title"
dgc_title.HeaderText = "Title"
DataGrid1.Columns.Add(dgc_title) Me.SqlDataAdapter1.Fill(Me.dsBooks1)
DataGrid1.DataBind()
End Sub// C#
private void Button1_Click(object sender, System.EventArgs e)
{
DataGrid1.AutoGenerateColumns = false;
DataGrid1.DataSource = this.dsBooks1;
DataGrid1.DataMember = "Books";
DataGrid1.DataKeyField = "bookid"; // Add two columns
BoundColumn dgc_id = new BoundColumn();
dgc_id.DataField = "bookid";
dgc_id.HeaderText = "ID";
dgc_id.ItemStyle.Width = new Unit(80);
DataGrid1.Columns.Add(dgc_id); BoundColumn dgc_title= new BoundColumn();
dgc_title.DataField = "title";
dgc_title.HeaderText = "Title";
DataGrid1.Columns.Add(dgc_title); this.sqlDataAdapter1.Fill(this.dsBooks1);
DataGrid1.DataBind();
}
Any time that you add controls to a page dynamically, you have the problem of persistence. Dynamically-added controls (or in this case, columns) are not automatically added to the page's view state, so you are obliged to add logic to the page to make sure the columns are available with each round trip.An excellent way to do this is to override the page's LoadViewState method, which gives you an early opportunity to reestablish columns in the DataGrid control. Because the LoadViewState method is called before the Page_Load event is raised, re-adding columns in the LoadViewState method assures that they are available for normal manipulation by the time any event code runs.The following example shows how you would expand the previous example to restore the columns each time the page runs again. As before, the Button1_Click handler adds two columns to the grid. (In this example, the event handler calls a separate routine called AddColumns to do so.) In addition, the page contains a simple Boolean property called DynamicColumnsAdded indicating whether the grid has had columns added; the property persists its value in view state. The LoadViewState method first calls the base class's LoadViewState method, which extracts view state information and configures controls with it. If columns were previously added to the grid (as per the DynamicColumnsAdded property), the method then re-adds them.' Visual Basic
Private Property DynamicColumnAdded() As Boolean
Get
If ViewState("ColumnAdded") Is Nothing Then
Return False
Else
Return True
End If
End Get
Set(ByVal Value As Boolean)
ViewState("ColumnAdded") = Value
End Set
End PropertyProtected Overrides Sub LoadViewState(ByVal savedState As Object)
MyBase.LoadViewState(savedState)
If Me.DynamicColumnAdded Then
Me.AddColums()
End If
End SubPrivate Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
' Check property to be sure columns are not added more than once
If Me.DynamicColumnAdded Then
Return
Else
Me.AddColums()
End If
End SubProtected Sub AddColums()
' Add two columns
Dim dgc_id As New BoundColumn()
dgc_id.DataField = "instock"
dgc_id.HeaderText = "In Stock?"
dgc_id.ItemStyle.Width = New Unit(80)
DataGrid1.Columns.Add(dgc_id) Dim dgc_title As New BoundColumn()
dgc_title.DataField = "title"
dgc_title.HeaderText = "Title"
DataGrid1.Columns.Add(dgc_title)
Me.DataGrid1.DataBind()
Me.DynamicColumnAdded = True
End Sub// C#
private bool DynamicColumnAdded{
get
{
object b = ViewState["DynamicColumnAdded"];
return (b == null) ? false : true;
}
set
{
ViewState["DynamicColumnAdded"] = value;
}
}protected override void LoadViewState(object savedState)
{
base.LoadViewState(savedState);
if (DynamicColumnAdded)
{
this.AddColumns();
}
}private void Button1_Click(object sender, System.EventArgs e)
{
if(this.DynamicColumnAdded != true)
{
this.AddColumns();
}
}private void AddColumns()
{
BoundColumn dgc_id = new BoundColumn();
dgc_id.DataField = "bookid";
dgc_id.HeaderText = "ID";
dgc_id.ItemStyle.Width = new Unit(80);
DataGrid1.Columns.Add(dgc_id); BoundColumn dgc_title= new BoundColumn();
dgc_title.DataField = "title";
dgc_title.HeaderText = "Title";
DataGrid1.Columns.Add(dgc_title); this.sqlDataAdapter1.Fill(this.dsBooks1);
DataGrid1.DataBind();
this.DynamicColumnAdded = true;
}