为什么会这样?
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.IO;
using System.Resources;
namespace PowerDataGrid
{
/// <summary>
/// WebCustomControl1 的摘要说明。
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:PowerDataGrid1 runat=server></{0}:PowerDataGrid1>")]
public class PowerDataGrid: System.Web.UI.WebControls.DataGrid
{
private string text;
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Text
{
get
{
return text;
}
set
{
text = value;
}
}
/// <summary>
/// 将此控件呈现给指定的输出参数。
/// </summary>
/// <param name="output"> 要写出到的 HTML 编写器 </param>
protected override void Render(HtmlTextWriter output)
{
output.Write(this.parseMarkup());
}
protected override void OnPreRender(System.EventArgs e)
{
base.OnPreRender(e);
ResourceManager manager = new ResourceManager( this.GetType() );
ResourceSet resources = manager.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true);
if( !Page.IsClientScriptBlockRegistered( "System.UI.WebControl.PowerDataGrid Library" ) )
{
String script = resources.GetString("ScrollTable");
this.Page.RegisterClientScriptBlock("System.UI.WebControl.PowerDataGrid Library", script );
this.Page.RegisterStartupScript("System.UI.WebControls.PowerDataGrid Init", "<script>makeScrollableTable('"+this.ID+"',true,'auto');</script>" );
}
}
private string parseMarkup()
{
// 插入THead标签和TBody标签
StringWriter writer = new StringWriter();
HtmlTextWriter buffer = new HtmlTextWriter(writer);
base.Render(buffer);
string pMarkup = writer.ToString();
// 找到第一个table标签的结尾也就是第一个>字符
pMarkup = pMarkup.Insert(pMarkup.IndexOf(">") + ">".Length, "<thead>");
// 将第一个tr闭区间用Thead包起来,现在第一个<thead>已经画出来了需要画
// 它的结尾</thead>和</tbody>,同样找到第一个</tr>来插入</thead>和</tdoby>
pMarkup = pMarkup.Insert( pMarkup.IndexOf("</tr>") + "</tr>".Length,"</thead><tbody>");
// 在最后一个</table>的前面插入一个</tbody>就可以了。
pMarkup = pMarkup.Replace("</table>", "</tbody></table>");
return pMarkup;
}
}
}
为什么在生成后添加到工具箱后,在拖到界面时说创建控件失败呢?
有哪位大侠帮忙解决呀!小弟在此拜谢了!