🎄 Merry Christmas! 🎅

Edi Wang

Microsoft MVP for Azure

Posts in August 2011

ASP.NET GridView超链接列取值

场景:开发一个简单的Web文件管理功能,第一列是指向文件的超链接,最后一列放一个删除按钮。现在要求按删除按钮后,删除对应的文件。 思路:获取当前行的第一列的值,然后调用File.Delete()方法。 按照以往的写法,我们会在GridView的SelectedIndexChanged事件中,先找到当前行: int i = GridView1.SelectedIndex; 然后通过 GridView1.Rows[i].Cells[0].Text来访问当前行第一列的数据。 但是,如果不幸遇到超链接列,这种写法取出的缺是空串。我研究了好久,最后发现,HyperLink Field在GridView中要当作Web Control来处理。所以必须先转换为HyperLink,然后才能访问其Text属性。写法如下: ((HyperLink)GridView1.Rows[i].Cells[0]. …
ASP.NET GridView

ASP.NET Repeater控件绑定List<T>泛型的写法

我们在开发分成架构的Web应用程序时,常常把数据库中的记录放到一个List中,做到了良好的封装。调用业务逻辑的程序猿也无需知道库表结构就可以直接使用“Model.属性”来访问各个字段的数据了。但在做显示的时候,初学者可能会碰到一些问题。以往大家在显示控件(如Repeater)上绑定的都是DataSet,ASPX页面里写的是“<%# Eval("字段名")%>”。那如何绑定一个List泛型呢? 其实,Repeater控件是支持绑定到业务对象的,并且我们也不再用Eval表达式了。看一个例子: 后台代码: GeekStudio.BLL.Blog optBlog = new GeekStudio.BLL.Blog(); Repeater1.DataSource = optBlog.GetModelList(); Repeater1.DataBind(); 其中,GetModelList()返回的是 …
ASP.NET Generics

Search and Destroy Process using C#

Recently, I saw an exam system that has a feature to monitor the process. As soon as prohibited software such as Communicator.exe is found, the process is immediately killed and reported to the server. I looked into it a little bit, and this feature is actually quite simple to implement. It is to use ManagementObjectSearcher to get a list of processes, then put them in a Collection, and then you can do it according to your own logic. Here's an example: get a list of processes, create a list of "banned" processes, find and kill processes. Note that you need to add a reference to System.Management in your project first.
C# Process