我的程序的代码: namespace Zh_WebUI.modules { using System; using System.Data; using System.Drawing; using System.Web; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.ComponentModel; using System.Collections; using System.Diagnostics; using System.Web.UI; public abstract class Leftbar : System.Web.UI.UserControl { int bar_unit_count=5; string[] contnt_title = new string[] {"档案管理","黄色IP管理","敏感IP管理","黄色关键字管理","敏感关键字管理"};//这种写法对 //string[] contnt_title = new string[5] //contnt_title[0]="aaa";///这种写法出错 private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 this.Controls.Add(new LiteralControl("<table cellpadding=3 cellspacing=3 width="+bar_width+" height="+bar_height+">\n")); this.Controls.Add(new LiteralControl("<tr><td valign=top><table border=0 cellpadding=0 cellspacing=0><tr><td width=127 height=18 valign=top></td></tr>\n")); for (int i=0; i<bar_unit_count;i++) { this.Controls.Add(new LiteralControl("<tr><td id=item"+i+" width=160><img src=add.gif width=12 height=12>"+contnt_title[i]+"\n")); this.Controls.Add(new LiteralControl("</td></tr>\n")); this.Controls.Add(new LiteralControl("<tr><td width=160 id=Content"+i+" style=Display:'none';>\n")); this.Controls.Add(new LiteralControl("<table border=0 width=100% cellpadding=0 cellspacing=0><tr><td width=100%>\n")); } this.Controls.Add(new LiteralControl("</td></tr></table></td></tr>")); } this.Controls.Add(new LiteralControl("</table>\n")); } } } 请帮帮忙!!!谢谢
@$#$@#%你的代码要写到方法体里面,在方法体之外只能有变量字段的声明和初始化的语句,所以要这样:public abstract class Leftbar : System.Web.UI.UserControl { int bar_unit_count=5; string[] contnt_title = new string[] {"档案管理","黄色IP管理","敏感IP管理","黄色关键字管理","敏感关键字管理"};//这种写法对 public Leftbar() { contnt_title[0]="aaa";//在构造器里面修改值 }
//...... }
楼主,我试了你的代码,没问题啊! string[] contnt_title = new string[5]; contnt_title[0]="aaa";
请大家帮帮我
contnt[1]="管理";
编译应没问题,你可能把“[“写成”[“角写成全角的
你真搞笑
contnt[1]="管理";你的]有可能用了中文的],你把输入法关了再敲
namespace Zh_WebUI.modules
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;
using System.Web.UI; public abstract class Leftbar : System.Web.UI.UserControl
{
int bar_unit_count=5;
string[] contnt_title = new string[]
{"档案管理","黄色IP管理","敏感IP管理","黄色关键字管理","敏感关键字管理"};//这种写法对
//string[] contnt_title = new string[5]
//contnt_title[0]="aaa";///这种写法出错
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
this.Controls.Add(new LiteralControl("<table cellpadding=3 cellspacing=3 width="+bar_width+" height="+bar_height+">\n"));
this.Controls.Add(new LiteralControl("<tr><td valign=top><table border=0 cellpadding=0 cellspacing=0><tr><td width=127 height=18 valign=top></td></tr>\n"));
for (int i=0; i<bar_unit_count;i++)
{
this.Controls.Add(new LiteralControl("<tr><td id=item"+i+" width=160><img src=add.gif width=12 height=12>"+contnt_title[i]+"\n"));
this.Controls.Add(new LiteralControl("</td></tr>\n"));
this.Controls.Add(new LiteralControl("<tr><td width=160 id=Content"+i+" style=Display:'none';>\n"));
this.Controls.Add(new LiteralControl("<table border=0 width=100% cellpadding=0 cellspacing=0><tr><td width=100%>\n"));
}
this.Controls.Add(new LiteralControl("</td></tr></table></td></tr>"));
}
this.Controls.Add(new LiteralControl("</table>\n"));
}
}
}
请帮帮忙!!!谢谢
{
int bar_unit_count=5;
string[] contnt_title = new string[]
{"档案管理","黄色IP管理","敏感IP管理","黄色关键字管理","敏感关键字管理"};//这种写法对
public Leftbar()
{
contnt_title[0]="aaa";//在构造器里面修改值
}
//......
}
string[] contnt_title = new string[5];
contnt_title[0]="aaa";