定制ObjectDataSource控件的设计视图外观

DataSource是2.0里面很重要的数据访问控件,不过DataSource类控件在设计视图总是Render成灰色的一块饼,除了ID什么信息也没有,看起不是太爽。不过现在发现了 System.Web.UI.Design.WebControls 这个namespace,“包含可用于扩展对 Web 服务器控件的设计时支持的类”。于是拿最有用的ObjectDataSource来试了试,结果可以做成这样:

上面那个就是定制的DataSource,把常用属性显示在设计视图上,用的时候更方便。下面是主要代码:

ContractedBlock.gif ExpandedBlockStart.gif VeryObjectDataSource
None.gif    [DisplayName("VeryObjectOataSource"), Description("VeryDxZ's ObjectDataSource")]
None.gif    [Designer(
"DxZ.Common.DataBinding.VeryObjectDataSourceDesigner")]
None.gif    
public class VeryObjectDataSource : ObjectDataSource
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif{
InBlock.gif
ExpandedBlockEnd.gif    }

None.gif
None.gif    
public class VeryObjectDataSourceDesigner : System.Web.UI.Design.WebControls.ObjectDataSourceDesigner
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif{
InBlock.gif        
public override string GetDesignTimeHtml()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            VeryObjectDataSource veryODS 
= (VeryObjectDataSource)this.Component;
InBlock.gif            StringBuilder htmlStrBuilder 
= new StringBuilder();
InBlock.gif
InBlock.gif            htmlStrBuilder.Append(
"<div style='margin:2px; padding:2px; background-color: buttonface; color: windowtext; font: messagebox;'>");
InBlock.gif                        
InBlock.gif            htmlStrBuilder.AppendFormat(
"<strong>{0}</strong> - {1}<br/>", veryODS.GetType().Name, veryODS.ID);
InBlock.gif            
if (veryODS.TypeName != null  && veryODS.TypeName != string.Empty)
InBlock.gif                htmlStrBuilder.AppendFormat(
"TypeName={0}<br/>", veryODS.TypeName);
InBlock.gif            
if (veryODS.DataObjectTypeName != null && veryODS.DataObjectTypeName != string.Empty)
InBlock.gif                htmlStrBuilder.AppendFormat(
"DataObject={0}<br/>", veryODS.DataObjectTypeName);
InBlock.gif
InBlock.gif            
if (veryODS.SelectMethod != null && veryODS.SelectMethod != string.Empty)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                htmlStrBuilder.Append(
"HasMethod=Select");
InBlock.gif
InBlock.gif                
if (veryODS.InsertMethod != null && veryODS.InsertMethod != string.Empty)
InBlock.gif                    htmlStrBuilder.Append(
",Insert");
InBlock.gif                
if (veryODS.UpdateMethod != null && veryODS.UpdateMethod != string.Empty)
InBlock.gif                    htmlStrBuilder.Append(
",Update");
InBlock.gif                
if (veryODS.DeleteMethod != null && veryODS.DeleteMethod != string.Empty)
InBlock.gif                    htmlStrBuilder.Append(
",Delete");
InBlock.gif
InBlock.gif                htmlStrBuilder.AppendFormat(
"<br/>Caching={0}, Paging={1}", veryODS.EnableCaching, veryODS.EnablePaging);
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            htmlStrBuilder.Append(
"</div>");
InBlock.gif            
InBlock.gif            
return htmlStrBuilder.ToString();
ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif    }

注意VeryObjectDataSource类的Attribute:
[Designer( " DxZ.Common.DataBinding.VeryObjectDataSourceDesigner " )]。
没有这句来指明Designer的话控件不会依照自定义的去Render。源代码见这里


上面这些只是外观的定制,当然还可以在ObjectDataSource构造函数加一些初始化的参数等等,方便程序设计时使用。同时,这种定制外观的方法对Xml和Substitution等同样Render不出什么内容的控件也适用哦。
 

转载于:https://www.cnblogs.com/dxz/archive/2006/07/21/custom_objectdatasource.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值