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

推荐订阅源

P
Palo Alto Networks Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
CERT Recently Published Vulnerability Notes
C
Cybersecurity and Infrastructure Security Agency CISA
S
Schneier on Security
S
Securelist
酷 壳 – CoolShell
酷 壳 – CoolShell
C
CXSECURITY Database RSS Feed - CXSecurity.com
Cyberwarzone
Cyberwarzone
Apple Machine Learning Research
Apple Machine Learning Research
S
SegmentFault 最新的问题
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
GbyAI
GbyAI
Security Latest
Security Latest
Last Week in AI
Last Week in AI
Microsoft Security Blog
Microsoft Security Blog
云风的 BLOG
云风的 BLOG
Recorded Future
Recorded Future
Webroot Blog
Webroot Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
TaoSecurity Blog
TaoSecurity Blog
C
Cisco Blogs
博客园 - 【当耐特】
Blog — PlanetScale
Blog — PlanetScale
Hugging Face - Blog
Hugging Face - Blog
B
Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Attack and Defense Labs
Attack and Defense Labs
The Last Watchdog
The Last Watchdog
U
Unit 42
阮一峰的网络日志
阮一峰的网络日志
Project Zero
Project Zero
WordPress大学
WordPress大学
L
LINUX DO - 最新话题
F
Fortinet All Blogs
L
LINUX DO - 热门话题
PCI Perspectives
PCI Perspectives
Simon Willison's Weblog
Simon Willison's Weblog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
MongoDB | Blog
MongoDB | Blog
Latest news
Latest news
P
Proofpoint News Feed
T
Threat Research - Cisco Blogs
The Hacker News
The Hacker News
爱范儿
爱范儿
O
OpenAI News
J
Java Code Geeks
T
The Exploit Database - CXSecurity.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More

博客园 - HelloSnoopy

一个最基本的WebService+Flash调用的实例 [转载]如何奔向程序员打工的出头之日? 一定要讲给孩子们的20个小故事 人脉对职业生涯最重要 (转) 爱情的10种样子,送给懂爱的朋友们 装了Enterprise Library.NET 200501release C#判断是否为数字的最好速度! 开源的 BugTracker.net 错误跟踪管理系统 Enjoy new year of 2005! Flash AS2 用EventDispatcher广播事件 设计模式随笔-让众口不再难调 CodeSmith使用心得 [专题]MVC构架模式 使用Microsoft Application Block之Cache Application 用一条SQL完成数据表的行统计 如何使IFrame的长宽与内容自动适应大小 为Project提供一个统一风格的DataGrid 用于读取树形任一节点下所有级别子节点的SqlServer UDF asp.net forums中定时器的应用
写了个用一个文件定义样式的DataGrid
HelloSnoopy · 2005-03-09 · via 博客园 - HelloSnoopy

支持样式类型为字符串或整型的设置,颜色设置暂不支持,不过这可以通过设置一个cssClass解决。
使用时只要设置下设置ConfigFile文件路径即可。
第一次写自定义控件,有些还需改进。
enhancedatagrid.cs

using System;
using System.Reflection;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Collections;
using System.Collections.Specialized;

namespace YOYOSOFT.Framework.Web.UI.Controls
{
    
/// <summary>
    
/// EnhanceDataGrid 的摘要说明。
    
/// </summary>

    [ToolboxData("<{0}:EnhanceDataGrid runat=server></{0}:EnhanceDataGrid>")]
    
public class EnhanceDataGrid : System.Web.UI.WebControls.DataGrid
    
{
        [Bindable(
true),
            Category(
"Appearance"),
            DefaultValue(
"")]
        
public string ConfigFile
        
{
            
get{return _configFile.Trim();}
            
set{_configFile = value;}
        }
string _configFile = string.Empty;

        
protected override void OnPreRender(EventArgs e)
        
{
            
if(this.ConfigFile.Length != 0)
            
{
                
string filePath = System.Web.HttpContext.Current.Server.MapPath(this.ConfigFile);
                NameValueCollection values 
= Globals.GetNameValues(filePath);
                SetStyle(values);
            }
    
            
base.OnPreRender (e);
        }


        
private void SetStyle(NameValueCollection values)
        
{
            
if(values == nullreturn;

            
string typeName;
            Type t 
= base.GetType();
            
string[] types;
            
for(int i=0; i<values.Count; i++)
            
{
                typeName 
= values.Keys[i];
                types 
= typeName.Split('.');
                PropertyInfo parentInfo 
= t.GetProperty(types[0]);
                
if(parentInfo == nullcontinue
                
                
if(types.Length >= 2)
                
{
                    PropertyInfo childInfo 
= parentInfo.PropertyType.GetProperty(types[1]);
                    SetPropertyValue(childInfo,
                        parentInfo.GetValue(
this,null),values[i]);
                }

                
else
                
{
                    SetPropertyValue(parentInfo,
this,values[i]);
                }

            }

        }

        
/// <summary>
        
/// 设置属性值
        
/// </summary>
        
/// <param name="p">要赋值的属性</param>
        
/// <param name="obj">属性所在对象</param>
        
/// <param name="val">属性值</param>

        private void SetPropertyValue(PropertyInfo p,object obj,string val)
        
{
            
if(p != null && 
                (p.PropertyType 
== typeof(int|| 
                p.PropertyType 
== typeof(string)))
            
{
                
if(Globals.IsInt(val))
                    p.SetValue(obj,
int.Parse(val),null);
                
else
                    p.SetValue(obj,val,
null);
            }

        }

    }

}

globals.cs:

XML配置文件: