定制ObjectDataSource控件的设计视图外观
2006-07-21 23:37
399 查看
DataSource是2.0里面很重要的数据访问控件,不过DataSource类控件在设计视图总是Render成灰色的一块饼,除了ID什么信息也没有,看起不是太爽。不过现在发现了 System.Web.UI.Design.WebControls 这个namespace,“包含可用于扩展对 Web 服务器控件的设计时支持的类”。于是拿最有用的ObjectDataSource来试了试,结果可以做成这样:
[DisplayName("VeryObjectOataSource"), Description("VeryDxZ's ObjectDataSource")]
[Designer("DxZ.Common.DataBinding.VeryObjectDataSourceDesigner")]
public class VeryObjectDataSource : ObjectDataSource
public class VeryObjectDataSourceDesigner : System.Web.UI.Design.WebControls.ObjectDataSourceDesigner
public override string GetDesignTimeHtml()
VeryObjectDataSource veryODS = (VeryObjectDataSource)this.Component;
StringBuilder htmlStrBuilder = new StringBuilder();
htmlStrBuilder.Append("<div style='margin:2px; padding:2px; background-color: buttonface; color: windowtext; font: messagebox;'>");
htmlStrBuilder.AppendFormat("<strong>{0}</strong> - {1}<br/>", veryODS.GetType().Name, veryODS.ID);
if (veryODS.TypeName != null && veryODS.TypeName != string.Empty)
htmlStrBuilder.AppendFormat("TypeName={0}<br/>", veryODS.TypeName);
if (veryODS.DataObjectTypeName != null && veryODS.DataObjectTypeName != string.Empty)
htmlStrBuilder.AppendFormat("DataObject={0}<br/>", veryODS.DataObjectTypeName);
if (veryODS.SelectMethod != null && veryODS.SelectMethod != string.Empty)
htmlStrBuilder.Append("HasMethod=Select");
if (veryODS.InsertMethod != null && veryODS.InsertMethod != string.Empty)
htmlStrBuilder.Append(",Insert");
if (veryODS.UpdateMethod != null && veryODS.UpdateMethod != string.Empty)
htmlStrBuilder.Append(",Update");
if (veryODS.DeleteMethod != null && veryODS.DeleteMethod != string.Empty)
htmlStrBuilder.Append(",Delete");
htmlStrBuilder.AppendFormat("<br/>Caching={0}, Paging={1}", veryODS.EnableCaching, veryODS.EnablePaging);
}
htmlStrBuilder.Append("</div>");
return htmlStrBuilder.ToString();
}
}
注意VeryObjectDataSource类的Attribute:
[Designer("DxZ.Common.DataBinding.VeryObjectDataSourceDesigner")]。
没有这句来指明Designer的话控件不会依照自定义的去Render。源代码见这里
上面这些只是外观的定制,当然还可以在ObjectDataSource构造函数加一些初始化的参数等等,方便程序设计时使用。同时,这种定制外观的方法对Xml和Substitution等同样Render不出什么内容的控件也适用哦。
[DisplayName("VeryObjectOataSource"), Description("VeryDxZ's ObjectDataSource")]
[Designer("DxZ.Common.DataBinding.VeryObjectDataSourceDesigner")]
public class VeryObjectDataSource : ObjectDataSource
public class VeryObjectDataSourceDesigner : System.Web.UI.Design.WebControls.ObjectDataSourceDesigner
public override string GetDesignTimeHtml()
VeryObjectDataSource veryODS = (VeryObjectDataSource)this.Component;
StringBuilder htmlStrBuilder = new StringBuilder();
htmlStrBuilder.Append("<div style='margin:2px; padding:2px; background-color: buttonface; color: windowtext; font: messagebox;'>");
htmlStrBuilder.AppendFormat("<strong>{0}</strong> - {1}<br/>", veryODS.GetType().Name, veryODS.ID);
if (veryODS.TypeName != null && veryODS.TypeName != string.Empty)
htmlStrBuilder.AppendFormat("TypeName={0}<br/>", veryODS.TypeName);
if (veryODS.DataObjectTypeName != null && veryODS.DataObjectTypeName != string.Empty)
htmlStrBuilder.AppendFormat("DataObject={0}<br/>", veryODS.DataObjectTypeName);
if (veryODS.SelectMethod != null && veryODS.SelectMethod != string.Empty)
htmlStrBuilder.Append("HasMethod=Select");
if (veryODS.InsertMethod != null && veryODS.InsertMethod != string.Empty)
htmlStrBuilder.Append(",Insert");
if (veryODS.UpdateMethod != null && veryODS.UpdateMethod != string.Empty)
htmlStrBuilder.Append(",Update");
if (veryODS.DeleteMethod != null && veryODS.DeleteMethod != string.Empty)
htmlStrBuilder.Append(",Delete");
htmlStrBuilder.AppendFormat("<br/>Caching={0}, Paging={1}", veryODS.EnableCaching, veryODS.EnablePaging);
}
htmlStrBuilder.Append("</div>");
return htmlStrBuilder.ToString();
}
}
注意VeryObjectDataSource类的Attribute:
[Designer("DxZ.Common.DataBinding.VeryObjectDataSourceDesigner")]。
没有这句来指明Designer的话控件不会依照自定义的去Render。源代码见这里
上面这些只是外观的定制,当然还可以在ObjectDataSource构造函数加一些初始化的参数等等,方便程序设计时使用。同时,这种定制外观的方法对Xml和Substitution等同样Render不出什么内容的控件也适用哦。
相关文章推荐
- Xpage中对定制控件在设计视图下外观的定制
- Xpage中对定制控件在设计视图下外观的定制
- 意外地发现,VS.NET从解决方案资源管理器中把ascx文件拖到aspx的设计视图里就可以添加用户控件
- [ASP.NET 控件实作 Day19] 控件设计阶段的外观
- vs2010 设计视图中控件无法加载,提示未将对象设置到对象的实例。
- 一步步学习微软InfoPath2010和SP2010--第三章节--表单设计基础:处理InfoPath布局、控件和视图(5)--理解数据绑定的基础
- 一步步学习微软InfoPath2010和SP2010--第三章节--表单设计基础:处理InfoPath布局、控件和视图(8)--视图
- UIAppearance定制控件的默认外观
- web developer tips (50):在 Visual Studio 的设计视图绝对定位控件
- [导入][ASP.NET 控件实作 Day19] 控件设计阶段的外观
- OCUI界面设计:滚动视图与分页控件初探
- 一步步学习微软InfoPath2010和SP2010--第三章节--表单设计基础:处理InfoPath布局、控件和视图(1)--表单布局
- [using_microsoft_infopath_2010]Chapter3 表单设计基础:使用InfoPath布局,控件,和视图
- 一步步学习微软InfoPath2010和SP2010--第三章节--表单设计基础:处理InfoPath布局、控件和视图(5)--理解数据绑定的基础
- 一步步学习微软InfoPath2010和SP2010--第三章节--表单设计基础:处理InfoPath布局、控件和视图(9)--添加第二个视图到Flight Delay表单
- 对windows 10 UWP中控件的外观进行定制(customization)
- web developer tips (76):在设计视图隐藏非可视控件
- 人立方关系搜索的silverlight控件外观定制揭秘
- ASP.NET中设计带事件定制控件
- 一步步学习微软InfoPath2010和SP2010--第三章节--表单设计基础:处理InfoPath布局、控件和视图(1)--表单布局