申明一个新对象???if(userName=="")
{yourClassname ttttt=new yourClassname();}
elseif
{yourClassname bbbbb=new yourClassname();}
elseif
{yourClassname ddddd=new yourClassname();}
{yourClassname ttttt=new yourClassname();}
elseif
{yourClassname bbbbb=new yourClassname();}
elseif
{yourClassname ddddd=new yourClassname();}
解决方案 »
- 紧急求助:关于.net repeater内嵌控件数据操作问题
- 帮忙看个正则表达式
- 关于web.config数据库连接字段解密
- visual studio.net运行环境提示……
- 新闻系统权限设计问题
- 对路径“C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\newprj\93b468af\b03b9be7\hash.web”的访问被拒绝。急
- asp.net怎么实现这个
- 请教Aspx显示乱码问题!
- 怎样用DataGrid中的按钮关闭模式窗口?
- PC web端如何实现调用每个用户的客户端应用程序
- 如何动态设置datagrid的某列的readonly=true这个属性?
- 一個關于datalist的問題
Public MyLabel As System.Web.UI.WebControls.Label根据需要Public不同的服务器端控件,如何实现?
NameFactory.cs
using System;namespace Factory
{
public class Namer{
protected string last;
protected string first;
public string getFirst(){
return first;
}
public string getLast(){
return last;
}
}
public class FirstFirst: Namer{
public FirstFirst(string s){
int i = s.LastIndexOf(" ");
if(i > 0){
first = s.Substring(0,i).Trim();
last = s.Substring(i+1).Trim();
}
else{
first = "";
last = s;
}
}
} public class LastFirst: Namer{
public LastFirst(string s){
int i = s.IndexOf(",");
if(i > 0){
last = s.Substring(0,i).Trim();
first = s.Substring(i+1).Trim();
}
else{
last = s;
first = "";
}
}
}
public class NameFactory{
public Namer getNamer(string entry){
int i = entry.IndexOf(",");
if(i>0){
return new LastFirst(entry);
}
else{
return new FirstFirst(entry);
}
}
}
}FactoryClient.cs
using System;
using Factory;public class FactoryClient{ public static void Main(string[] Args)
{
string name = "";
while((name.Trim()).Length == 0){
name = Console.ReadLine();
} NameFactory nf = new NameFactory();
Namer n = nf.getNamer(name);
Console.WriteLine(n.getFirst() + " " + n.getLast());
}
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>datagrid</title>
<meta content="Microsoft Visual Studio .NET 7.0" name="GENERATOR">
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体"></FONT>
<DIV id="disply" style="Z-INDEX: 102; LEFT: 232px; WIDTH: 208px; POSITION: absolute; TOP: 32px; HEIGHT: 144px" runat="server"></DIV>
<FONT face="宋体"></FONT><FONT face="宋体"></FONT><FONT face="宋体"></FONT><FONT face="宋体">
</FONT>
</form>
</body>
</HTML>=============================================
'datagrid.aspx.vbImports System.Web.UI.HtmlControls
Imports System.Data
Imports System.Data.SqlClient
Public Class datagrid
Inherits System.Web.UI.Page
' Protected WithEvents disply As System.Web.UI.HtmlControls.HtmlGenericControl#Region " Web 窗体设计器生成的代码 " '该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub#End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
Dim disply As System.Web.UI.HtmlControls.HtmlGenericControl
Dim DataGrid1 As New System.Web.UI.WebControls.DataGrid()
disply.Controls.Add(DataGrid1) '将DataGrid控件动态加入到Div元素中
Dim conn As New SqlConnection()
'连接数据库字符串
conn.ConnectionString = "data source=(local);initial catalog=ga;password=lovesong;user id=sa"
conn.Open()
Dim strSel As String
strSel = "select * from tbl_pcs"
'SqlDataAdapter是在DataSet与关系数据库间起桥梁作用
Dim objDataAdapter As New SqlDataAdapter(strSel, conn)
Dim objDataSet As New DataSet()
objDataAdapter.Fill(objDataSet, "pcs")
DataGrid1.DataSource = objDataSet.Tables("pcs").DefaultView '为DataGrid控件指定数据源
DataGrid1.AllowPaging = True '是否允许分页属性
DataGrid1.PageSize = "10" '每页的数量
' DataGrid1.PagerStyle.Mode = PagerMode.NumericPages '确定分页用数字表示页码
'指定用一个自定义格式作为前后页跳转
DataGrid1.PagerStyle.NextPageText = "Next" '这和PagerMode.NumericPages属性只能选择其一
DataGrid1.PagerStyle.PrevPageText = "Prev"
Response.Write(DataGrid1.PageCount) '写出DataGrid总共有多少页
' DataGrid1.Columns[0].HeaderText = "ID号"
' DataGrid1.Columns(0)
AddHandler DataGrid1.PageIndexChanged, AddressOf LogGridPage 'AddHandler语句将事件进行绑定
DataGrid1.DataBind() End Sub
Sub LogGridPage(ByVal sender As System.Object, ByVal e As DataGridPageChangedEventArgs)
sender.CurrentPageIndex = e.NewPageIndex
sender.DataBind()
End SubEnd Class
<DIV id="disply" style="Z-INDEX: 102; LEFT: 232px; WIDTH: 208px; POSITION: absolute; TOP: 32px; HEIGHT: 144px" runat="server"></DIV>
我将在Public里声明的disply 注释
' Protected WithEvents disply As System.Web.UI.HtmlControls.HtmlGenericControl
放到PageLoad里
Dim disply As System.Web.UI.HtmlControls.HtmlGenericControl
然后运行会报以下错误:未将对象引用设置到对象的实例。 disply.Controls.Add(DataGrid1) '将DataGrid控件动态加入到Div元素中
难道不可以放到子程序里定义?
兄弟我不理解,可否做下解释??
我加入了以下两句报了值不能为空。参数名:child 的错.
Dim disply As System.Web.UI.HtmlControls.HtmlGenericControl
Me.Controls(1).Controls.Add(disply)不知是何原因????
将 "<div>内容</div>"整个添加到 PlaceHolder的 Controls 中去。
Dim disply As System.Web.UI.HtmlControls.HtmlGenericControl
Dim objControls As New PlaceHolder()
objControls.Controls.Add(disply)还是报原来一样的错误
值不能为空。参数名:child
有谁能告诉我为什么吗????
可否解释一下Me.Controls(1).Controls.Add(disply)中的controls(1)是什么意思和起什么作用?
this.Controls[1] is System.Web.UI.HtmlControls.HtmlForm
you use
Response.Write(this.Controls[1].ToString());see url
http://www.csdn.net/expert/topic/914/914057.xml?temp=.1204492
“子”控件