写了自定义控件,也给相应的网站项目添加了引用,但是从工具箱面板上把该自定义控件拖到页面时说:
呈现控件时出错初始化字符串格式不符合规范,是哪里错误了呢?
一下是自定义控件代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data;
using System.Xml;namespace WebControlLibrary1
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>")]
public class showAd : WebControl
{
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public string Text
{
get
{
String s = (String)ViewState["Text"];
return ((s == null) ? String.Empty : s);
} set
{
ViewState["Text"] = value;
}
}
[Bindable(true)]
[Category("appearance")]
[DefaultValue("")]
[Localizable(true)]
public string type
{
get
{
String s = (String)ViewState["type"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["type"] = value;
}
} [Bindable(true)]
[Category("appearance")]
[DefaultValue("")]
[Localizable(true)]
public string adid
{
get
{
String s = (String)ViewState["adid"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["adid"] = value;
}
} [Bindable(true)]
[Category("appearance")]
[DefaultValue("~/App_Data/maikou.mdb")]
[Localizable(true)]
public string dbpath
{
get
{
String s = (String)ViewState["dbpath"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["dbpath"] = value;
}
} [Bindable(true)]
[Category("appearance")]
[DefaultValue("")]
[Localizable(true)]
public String showNum
{
get
{
String s = (String)ViewState["shownum"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["shownum"] = value;
}
} [Bindable(true)]
[Category("appearance")]
[DefaultValue("")]
[Localizable(true)]
public string cssStyle
{
get
{
String s = (String)ViewState["cssStyle"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["cssStyle"] = value;
}
} protected override void RenderContents(HtmlTextWriter output)
{
string connstr = MapPathSecure("~/App_Data/maikou.mdb");
if (dbpath != null)
{
connstr = dbpath;
} OleDbConnection conn = new OleDbConnection(connstr);
conn.Open(); string sql;
if (type != null && adid != null)
{
sql = "select * from ads where types='" + type + "' and id='" + adid + "' order by id desc";
}
else if (type != null)
{
sql = "select * from ads where types='" + type + "' order by id desc";
}
else if (adid != null)
{
sql = "select * from ads where id='" + adid + "' order by id desc";
}
else
{
sql = "select * from ads order by id desc";
} OleDbDataAdapter oda = new OleDbDataAdapter(sql, conn);
DataSet ds = new DataSet();
int count = oda.Fill(ds, "adtable");
DataTable thistable = ds.Tables["adtable"];
if (count > 0)
{
if (count > Convert.ToInt32(showNum))
{
count = Convert.ToInt32(showNum);
StringBuilder build = new StringBuilder();
build.Append("<div style=\"border:1px solid #ffcc99;\">");
for (int i = 0; i < count; i++)
{
build.Append("<div style=\"border:1px dashed #cccccc;\"><a href=\"" + thistable.Rows[i]["url"].ToString() + "\" target=\"black\">" + thistable.Rows[i]["name"].ToString() + "</a></div>");
}
build.Append("</div>");
Text = build.ToString();
}
}
else
{
Text = "暂时没有数据";
} output.Write(Text); }
}
}
呈现控件时出错初始化字符串格式不符合规范,是哪里错误了呢?
一下是自定义控件代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data;
using System.Xml;namespace WebControlLibrary1
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>")]
public class showAd : WebControl
{
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public string Text
{
get
{
String s = (String)ViewState["Text"];
return ((s == null) ? String.Empty : s);
} set
{
ViewState["Text"] = value;
}
}
[Bindable(true)]
[Category("appearance")]
[DefaultValue("")]
[Localizable(true)]
public string type
{
get
{
String s = (String)ViewState["type"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["type"] = value;
}
} [Bindable(true)]
[Category("appearance")]
[DefaultValue("")]
[Localizable(true)]
public string adid
{
get
{
String s = (String)ViewState["adid"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["adid"] = value;
}
} [Bindable(true)]
[Category("appearance")]
[DefaultValue("~/App_Data/maikou.mdb")]
[Localizable(true)]
public string dbpath
{
get
{
String s = (String)ViewState["dbpath"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["dbpath"] = value;
}
} [Bindable(true)]
[Category("appearance")]
[DefaultValue("")]
[Localizable(true)]
public String showNum
{
get
{
String s = (String)ViewState["shownum"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["shownum"] = value;
}
} [Bindable(true)]
[Category("appearance")]
[DefaultValue("")]
[Localizable(true)]
public string cssStyle
{
get
{
String s = (String)ViewState["cssStyle"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["cssStyle"] = value;
}
} protected override void RenderContents(HtmlTextWriter output)
{
string connstr = MapPathSecure("~/App_Data/maikou.mdb");
if (dbpath != null)
{
connstr = dbpath;
} OleDbConnection conn = new OleDbConnection(connstr);
conn.Open(); string sql;
if (type != null && adid != null)
{
sql = "select * from ads where types='" + type + "' and id='" + adid + "' order by id desc";
}
else if (type != null)
{
sql = "select * from ads where types='" + type + "' order by id desc";
}
else if (adid != null)
{
sql = "select * from ads where id='" + adid + "' order by id desc";
}
else
{
sql = "select * from ads order by id desc";
} OleDbDataAdapter oda = new OleDbDataAdapter(sql, conn);
DataSet ds = new DataSet();
int count = oda.Fill(ds, "adtable");
DataTable thistable = ds.Tables["adtable"];
if (count > 0)
{
if (count > Convert.ToInt32(showNum))
{
count = Convert.ToInt32(showNum);
StringBuilder build = new StringBuilder();
build.Append("<div style=\"border:1px solid #ffcc99;\">");
for (int i = 0; i < count; i++)
{
build.Append("<div style=\"border:1px dashed #cccccc;\"><a href=\"" + thistable.Rows[i]["url"].ToString() + "\" target=\"black\">" + thistable.Rows[i]["name"].ToString() + "</a></div>");
}
build.Append("</div>");
Text = build.ToString();
}
}
else
{
Text = "暂时没有数据";
} output.Write(Text); }
}
}
解决方案 »
- ASP.NET读取EXECL文件的问题
- Asp.net获取客户端唯一标识
- Any source code ? Datalist paging for Gallery
- 如何动态引用一个样式表文件到网页的<head>中? asp.net (C#)
- 能否通过编程的方式,获得某一个网址是否存在
- 大家平时开发软件用什么工具写代码呀?
- 水晶报表显示问题
- 请教一个生成缩略图的问题,高手们可以帮忙一下
- 一些网站800*600就全屏,1024网页就居中请问是如何做的?主要用什么思想和方法?谢谢指教
- 我要求用户输入一个姓名,要求必须是汉字,要怎么进行判断全是汉字
- 请教问题。。。
- 接近崩溃,datagrid e.Item.Cells[5].Text取不到值!大家帮忙啊!
在StringBuilder build = new StringBuilder();下断点调试,
看是哪行Append的东西有问题了,多数是带些非法自发什么的,譬如是\错误使用
build.Append("<div style=\‘border:1px solid #ffcc99;\’>");
for (int i = 0; i < count; i++)
{
build.Append("<div style=\‘border:1px dashed #cccccc;\’><a href=\‘" + thistable.Rows[i]["url"].ToString() + "\’ target=\‘black\’>" + thistable.Rows[i]["name"].ToString() + "</a></div>");
}