当前位置: 首页 > news >正文

网站 默认页/宁波seo咨询

网站 默认页,宁波seo咨询,wordpress支付界面出现500,上市公司网站建设示例代码请参考此篇一.为数据绑定控件(GridView)自定义列(DataControlField)本来asp.net1.1中已经存在DataGrid了,其中为我们提供了丰富的数据字段类型(即不同绑定列)&#xff0c;如下代码<asp:DataGrid ID"dg1"runat"server"><Columns><as…
示例代码请参考此篇


一.为数据绑定控件(GridView)自定义列(DataControlField)

本来asp.net1.1中已经存在DataGrid了,其中为我们提供了丰富的数据字段类型(即不同绑定列),如下代码

None.gif            <asp:DataGrid ID="dg1" runat="server">
None.gif            
<Columns>
None.gif            
<asp:BoundColumn></asp:BoundColumn>
None.gif            
<asp:ButtonColumn></asp:ButtonColumn>
None.gif            
<asp:HyperLinkColumn></asp:HyperLinkColumn>
None.gif            
<asp:TemplateColumn></asp:TemplateColumn>
None.gif            
</Columns>
None.gif            
</asp:DataGrid>
网上也有介绍扩展DataGridColumn类的方法,asp.net2.0新增的GridView定义了全新的数据列,其也可以用于DetailsView,即DataControlField类

来看下其内置列的实现



DataControlField类为数据列的基类,其派生类相信大家都很熟悉,如下图



当然我们这里讨论的不是怎么使用这些列,而是如何实现自定义列的过程.实现方法跟以前的有些相似,还是抽象类DataControlField为我们实现了一些常用方法,并定义了一些必须让我们去实现的方法,让字类去重写.

下面列出常用相关的方法

这里以自定义CalendarField列为例

看DataControlField的CloneField()方法,先创建对象,再复制属性
None.gif    protected internal DataControlField CloneField()
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif{
InBlock.gif        DataControlField newField 
= this.CreateField();
InBlock.gif        
this.CopyProperties(newField);
InBlock.gif        
return newField;
ExpandedBlockEnd.gif    }

None.gif


1.创建列对象

DataControlField提供了CopyProperties 方法,此工作一定要做

None.gif        protected override DataControlField CreateField()
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif{
InBlock.gif            
return new CalendarField();
ExpandedBlockEnd.gif        }


2.复制属性

DataControlField提供了CopyProperties 方法

首先要先定义你需要的属性,然后将属性复制给CloneField方法中创建的对象,在更改属性时要记得调用OnFieldChanged方法,通知DataControlField对象状态发生变化,触发FieldChanged事件

ContractedBlock.gifExpandedBlockStart.gif
ContractedBlock.gifExpandedBlockStart.gif        Custom properties#region Custom properties
InBlock.gif        
// *******************************************************************
InBlock.gif        
// PROPERTY: DataField
InBlock.gif        
// Indicates the field providing the date in view mode
InBlock.gif
        public virtual string DataField
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
object o = this.ViewState["DataField"];
InBlock.gif                
if (o != null)
InBlock.gif                    
return (string) o;
InBlock.gif                
return String.Empty;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                ViewState[
"DataField"= value;
InBlock.gif                OnFieldChanged();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
InBlock.gif        
// *******************************************************************
InBlock.gif        
// PROPERTY: ReadOnly
InBlock.gif        
// Indicates the field from which the text of the drop-down items is taken
InBlock.gif
        public virtual bool ReadOnly
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
object o = base.ViewState["ReadOnly"];
InBlock.gif                
if (o != null)
InBlock.gif                    
return (bool) o;
InBlock.gif                
return false;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
base.ViewState["ReadOnly"= value;
InBlock.gif                OnFieldChanged();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
InBlock.gif        
// *******************************************************************
InBlock.gif        
// PROPERTY: DataFormatString
InBlock.gif        
// Indicates the format string for the date 
InBlock.gif
        public virtual string DataFormatString
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
object o = this.ViewState["DataFormatString"];
InBlock.gif                
if (o != null)
InBlock.gif                    
return (string)o;
InBlock.gif                
return String.Empty;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                ViewState[
"DataFormatString"= value;
InBlock.gif                OnFieldChanged();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedBlockEnd.gif        
#endregion

None.gif
None.gif        
// *******************************************************************
None.gif        
// METHOD: CopyProperties
None.gif        
//  
None.gif
        protected override void CopyProperties(DataControlField newField)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif{
InBlock.gif            ((CalendarField)newField).DataField 
= this.DataField;
InBlock.gif            ((CalendarField)newField).DataFormatString 
= this.DataFormatString;
InBlock.gif            ((CalendarField)newField).ReadOnly 
= this.ReadOnly;
InBlock.gif
InBlock.gif            
base.CopyProperties(newField);
ExpandedBlockEnd.gif        }

3.初始化单元格状态(InitializeCell方法)

即把你自己定义的东西添加到表格中。这里需要注意顺序

我们知道GridView的单元格(即DataControlCellType)分为三种类型,页眉,页脚,数据项,到了确定是数据项以后,又要给数据行分类型

如编辑,插入,交替,选中等(即DataControlRowState)

BoundField在普通状态下是文本,在编辑状态下是TextBox.这里就是要做这个工作,在不同状态下,加载不同控件。如下代码

None.gif      public override void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif{
InBlock.gif
InBlock.gif            
base.InitializeCell(cell, cellType, rowState, rowIndex);
InBlock.gif
InBlock.gif            
//如果为数据项
InBlock.gif
            if (cellType == DataControlCellType.DataCell)
InBlock.gif                InitializeDataCell(cell, rowState);
ExpandedBlockEnd.gif        }

None.gif
None.gif        
protected virtual void InitializeDataCell(DataControlFieldCell cell, DataControlRowState rowState)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif{
InBlock.gif            Control ctrl 
= null;
InBlock.gif
InBlock.gif            DataControlRowState state 
= rowState & DataControlRowState.Edit;
InBlock.gif
InBlock.gif            
//根据状态加载不同控件
InBlock.gif
            if ((!ReadOnly && (state != DataControlRowState.Normal)) || rowState == DataControlRowState.Insert)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Calendar cal 
= new Calendar();
InBlock.gif                cal.ToolTip 
= this.HeaderText;
InBlock.gif                cell.Controls.Add(cal);
InBlock.gif
InBlock.gif                
if ((DataField.Length != 0&&
InBlock.gif                    (DataField.Length 
!= 0))
InBlock.gif                    ctrl 
= cal;
InBlock.gif
InBlock.gif                _inInsertMode 
= rowState == DataControlRowState.Insert;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else if (DataField.Length != 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                ctrl 
= cell;
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
//给控件赋绑定的值
InBlock.gif
            if ((ctrl != null&& Visible)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                ctrl.DataBinding 
+= new EventHandler(this.OnBindingField);
ExpandedSubBlockEnd.gif            }

ExpandedBlockEnd.gif        }

4.实现数据交互(ExtractValuesFromCell方法)

第三步骤是显示信息,这里则需要提取字段的值,然后添加到dictionary集合中.具体其他操作暂且不管。

None.gif        public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif{
InBlock.gif            
object selectedValue = null;
InBlock.gif            
if (cell.Controls.Count > 0
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Calendar cal 
= cell.Controls[0as Calendar;
InBlock.gif
InBlock.gif                
if (cal == null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
throw new InvalidOperationException("CalendarField could not extract control.");
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
InBlock.gif                    selectedValue 
= cal.SelectedDate;
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
// Add the value to the dictionary
InBlock.gif
            if (dictionary.Contains(DataField))
InBlock.gif                dictionary[DataField] 
= selectedValue;
InBlock.gif            
else
InBlock.gif                dictionary.Add(DataField, selectedValue);
ExpandedBlockEnd.gif        }

5.给列添加设计时支持

BoundField列在有字段绑定的情况下,在设计时显示如下



其是通过GetDesignTimeValue方法实现的,如可以这样定义

None.gif        protected virtual string GetDesignTimeValue()
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif{
InBlock.gif            
return "<select><option>Databound Date</option></select>";
ExpandedBlockEnd.gif        }

在页面效果如下

 

好了,大致步骤就如此,你只需要熟悉上面方法,照着步骤做一遍就可以了.
另外还有DataGrid的DataGridColumn,如果你理解上面DataControlField的做法的话,DataGridColumn的实现关键方法则是InitializeCell,方法比较相似.但其没有ExtractValuesFromCell方法,因为DataGrid当时还没有这么的智能化的自动编辑功能.

二.数据源控件控件自定义参数

数据源控件我们也比较常用,所以要学习下如何自定义参数,如下图,为内置已经实现的几个参数类.



我们还是关注下Parameter类,其主要提供了一个空的Evaluate 方法给,派生类需要实现此方法返回经过更新的值.其实现比较简单,来看下其内部QueryStringParameter的实现过程.应该说没什么难度.抓住重点就好


None.gifpublic class QueryStringParameter : Parameter
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif        
public QueryStringParameter()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
protected QueryStringParameter(QueryStringParameter original) : base(original)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
this.QueryStringField = original.QueryStringField;
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
public QueryStringParameter(string name, string queryStringField) : base(name)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
this.QueryStringField = queryStringField;
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
public QueryStringParameter(string name, TypeCode type, string queryStringField) : base(name, type)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
this.QueryStringField = queryStringField;
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
protected override Parameter Clone()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
return new QueryStringParameter(this);
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
protected override object Evaluate(HttpContext context, Control control)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
if ((context != null&& (context.Request != null))
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return context.Request.QueryString[this.QueryStringField];
ExpandedSubBlockEnd.gif        }

InBlock.gif        
return null;
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif        
public string QueryStringField
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
get
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
object obj2 = base.ViewState["QueryStringField"];
InBlock.gif            
if (obj2 == null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return string.Empty;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return (string) obj2;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
set
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (this.QueryStringField != value)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
base.ViewState["QueryStringField"= value;
InBlock.gif                
base.OnParameterChanged();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif


三.属性集合

以上的
DataControlFieldParameter都具有集合类型DataControlFieldCollectionParameterCollection

有时候扩展了以后可能还需要更改集合类型,因为有时候集合类型是在开发人员在功能已经实现的情况下编写的.现在的扩展势必需要发生一些改变.而属性类型一更改,控件内部的集合属性也需要更改.当然偷懒的话就不改了,这么一改比较麻烦.但这种事情还是会碰到的.这里就提一下.

好了就这么写一下,希望对大家有帮助.本人已经在上海的某家公司工作.
今后的工作大多会更多地设计到控件的开发上,希望与大家多交流

转载于:https://www.cnblogs.com/Clingingboy/archive/2007/06/05/771913.html

http://www.lbrq.cn/news/757225.html

相关文章:

  • 南通优普网站建设团队/点击器 百度网盘
  • 通州区网站制作/海南百度推广总代理商
  • 网站建设 6万/如何注册域名
  • 上外国网站用什么dns/百度推广代理怎么加盟
  • 有什么做服装的网站好/长春网站建设设计
  • 医药b2b平台排名/广东网站seo策划
  • 网站开发达成口头协议算不算诈骗/临汾网络推广
  • 中企动力建站怎么样/网络营销专业学什么
  • wordpress翻书/谷歌seo 优化
  • 网站排行怎么做/免费网站推广群发软件
  • app在线生成网站/天津网站优化
  • 济南网站建站公司/奇零seo赚钱培训
  • 寻找五屏网站建设/百度预测大数据官网
  • 该网站未在腾讯云备案/郑州网络公司排名
  • 花钱做网站注意些什么/电脑培训机构哪个好
  • 营销型网站优势/新东方一对一辅导价格
  • 芜湖市建设银行支行网站/黑帽seo是作弊手法
  • 深圳建设网站费用/推推蛙贴吧优化
  • 上海网站设计排名/搜索引擎广告投放
  • 满城网站建设/网络平台
  • 炎陵网站建设/网站权重排名
  • 住房和建设局/百度seo优化工具
  • 企业建立网站的必要性/推蛙网络
  • 网站项目设计/知乎营销平台
  • 做网站接雕塑业务/百度站内搜索的方法
  • 电子商务网站的建设视频/seo搜索引擎优化公司
  • 南昌网站搜索排名/企业百度推广怎么收费
  • 卖域名的公司 骗做网站/百度快照优化培训班
  • 网站开发需要准备什么材料/灰色项目推广渠道
  • wordpress微站/深圳做推广哪家比较好
  • 【数据结构】-2- 泛型
  • FPGA串口通信实现方案
  • AI杀死的第一个仪式:“hello world”
  • 2025年最新油管视频下载,附MassTube下载软件地址
  • 区块链:用数学重构信任的数字文明基石
  • MuMu模拟器Pro Mac 安卓手机平板模拟器(Mac中文)