惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
G
Google Developers Blog
Spread Privacy
Spread Privacy
I
InfoQ
V
V2EX
S
Schneier on Security
小众软件
小众软件
C
CERT Recently Published Vulnerability Notes
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Attack and Defense Labs
Attack and Defense Labs
云风的 BLOG
云风的 BLOG
The Hacker News
The Hacker News
S
SegmentFault 最新的问题
C
Cybersecurity and Infrastructure Security Agency CISA
NISL@THU
NISL@THU
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
GbyAI
GbyAI
Latest news
Latest news
S
Secure Thoughts
Project Zero
Project Zero
MongoDB | Blog
MongoDB | Blog
I
Intezer
Security Latest
Security Latest
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
N
Netflix TechBlog - Medium
V2EX - 技术
V2EX - 技术
量子位
T
Threatpost
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
T
Tor Project blog
A
Arctic Wolf
Microsoft Security Blog
Microsoft Security Blog
T
The Exploit Database - CXSecurity.com
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Check Point Blog
博客园 - Franky
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
L
LINUX DO - 热门话题

博客园 - jierry

ASP.NET2.0控件一览---标准控件(2) ASP.NET2.0控件一览---标准控件(1) 控件开发时两种JS嵌入资源方式的使用 - jierry - 博客园 T-SQL tips(1)临时表和表变量 Flash Control for ASP.NET 2.0-Include Flash movies in your aspx pages 为DataGrid创建自定义列控件(四) 为DataGrid创建自定义列控件(二) 为DataGrid创建自定义列控件(一) (转)SQLServer和Oracle的常用函数对比 《Effective C#》读书笔记(4) 《Effective C#》读书笔记(3) 《Effective C#》读书笔记(2) 《Effective C#》读书笔记(1) 选择合适的数据控件 自带图层的链接控件(DKLinks 1.0.0.323 ) 关于CodeBuild V3.0的一些想法 小工具:SQL存储过程解密修改工具 交叉表应用-成绩统计 现在提供第一版的存储过程生成器下载,欢迎大家试用
为DataGrid创建自定义列控件(三) - jierry - 博客园
jierry · 2005-10-28 · via 博客园 - jierry

        通过前面两篇文章的学习,大家对自定义列控件的基本知识都掌握了,本节为大家巩固下前面学习的东西,以上篇文章为基础,扩展审查列控件,使它能审查多个单词。
        我们通过把要检查的单词和替换的单词保存在XML文件中,这样便于修改。
        
        XML文件如下(Text.xml):

<?xml version="1.0" encoding="utf-8" ?> 
<censors> 
  
<censor> 
    
<find>wit</find> 
    
<replace>w*t</replace> 
  
</censor> 
  
<censor> 
    
<find>ra</find> 
    
<replace>*a</replace> 
  
</censor> 
</censors> 

        完整代码如下:

    public class CensorColumn :DataGridColumn
    
{
        
private string m_DataFiled;
        
public string DataField
        
{
            
get
            
{
                
return this.m_DataFiled;
            }

            
set
            
{
                
this.m_DataFiled = value;
            }

        }


        
//检查文本
        private string m_XmlFile;
        
public string XmlFile
        
{
            
get
            
{
                
return this.m_XmlFile;
            }

            
set
            
{
                
this.m_XmlFile = value;
            }

        }


        
public override void InitializeCell(TableCell cell, int columnIndex, ListItemType itemType)
        
{
            
base.InitializeCell (cell, columnIndex, itemType);
            
if((itemType == ListItemType.AlternatingItem)||(itemType == ListItemType.SelectedItem)||(itemType == ListItemType.Item))
            
{
                cell.DataBinding 
+= new EventHandler(PerformDataBinding);
            }

        }


        
private void PerformDataBinding(object sender, System.EventArgs e)
        
{
            TableCell cell 
= (TableCell)sender;
            DataGridItem gridItem 
= (DataGridItem)cell.NamingContainer;
            Object dataItem 
= gridItem.DataItem;

            
if(!this.m_DataFiled.Equals(string.Empty))
            
{
                cell.Text 
= PerformShip((string)DataBinder.Eval(dataItem, DataField));
            }

        }


        
private string PerformShip(string text)
        
{
            
if(m_XmlFile.Equals(string.Empty))
            
{
                
return text;
            }

            
else 
            
{
                
return PerformXml(text);
            }
    
        }


        
private string PerformXml(string text)
        
{
            
string file = HttpContext.Current.Server.MapPath(this.XmlFile);
            
if(!File.Exists(file))
            
{
                
return text;
            }

            
else
            
{
                XmlDocument doc 
= new XmlDocument();
                doc.PreserveWhitespace 
= true;
                doc.Load(file);
                XmlNode node 
= doc.DocumentElement;    
                XmlNodeList findNodes 
= node.SelectNodes("/censors/censor/find");        
                XmlNodeList replaceNodes 
= node.SelectNodes("/censors/censor/replace");
                
int i;
                
for(i=0;i<findNodes.Count;i++)
                
{
                    text 
= text.Replace(findNodes.Item(i).InnerText,replaceNodes.Item(i).InnerText);
                }

                
return text;
            }

        }


    }

        在DataGrid中添加列控件:

                <Columns>
                    
<custcols:CensorColumn XmlFile="Text.xml" DataField="ShipCountry"></custcols:CensorColumn>
                
</Columns>

    效果图:

        
        一口气写完了三篇,相信大家看完后掌握了自定义列控件开发的基本知识。这三篇文章都是从很基础的角度讲述列控件的开发,如果你想要进一步的提高,可以看看lovecherry的这篇文章

http://lovecherry.cnblogs.com/lovecherry/archive/2005/05/01/148504.html