以前在asp很难实现代码重用,asp.net很好的解决了这个问题,以下是我写的DataGrid,继承DataGrid,加进了升降序/全并单元格/自动求和功能,原理很简单,但很好的实现的代码重用.
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
namespace SunService
{
/// <summary>
/// Summary description for DataGrid.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:DataGrid runat=server></{0}:DataGrid>")]
public class DataGrid : System.Web.UI.WebControls.DataGrid
{
private string text;
private SqlDataAdapter adp;
private DataSet ds;
private DataView view;
private string[] arritem;
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Text
{
get
{
return text;
}
set
{
text = value;
}
}
/// <summary>
/// protect SortDirection 排序方向
/// </summary>
public string SortDirection
{
get
{
if(ViewState["SortDirection"]==null)
{
return null;
}
else
{
if(ViewState["SortDirection"].ToString()=="")
{
return null;