再问!自定义控件问题 写了自定义控件,也给相应的网站项目添加了引用,但是从工具箱面板上把该自定义控件拖到页面时说:呈现控件时出错初始化字符串格式不符合规范,是哪里错误了呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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); } }} 我是一个.net程序员 我的方向在哪?该怎么发展?大哥大姐们,请不吝赐教 求助。。 请问如何解决这个错误啊! ASP.NET 请问如何获取WEB页面生成的源码。将其转入指定的文本文件中。 web.config有一段我不清楚,谁能告诉我??急 不关闭模式窗体如何达到与父窗体的交互 从数据库SELECT一个数据,怎么把它赋值给变量? 怎么显示控件的内容为空??明明有内容!!! GridView翻页问题 DropDownList控件,通过数据绑定以后,如何设置默认值?! asp.net javascript这个是什么意思? jquery 的小问题
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); }
}
}