我們來看看使用效果
實體類
public class CityInfo
{
public string City { get; set; }
public float Salary { get; set; }
}
綁定
if (!IsPostBack)
{
var s = new List<CityInfo> {
new CityInfo(){ City = "上海",Salary=8000f },
new CityInfo() { City = "杭州",Salary=8000f },
new CityInfo() { City = "北京",Salary=6000f },
new CityInfo() { City = "廣州",Salary=6000f },
new CityInfo() { City = "深圳",Salary=4000f },
new CityInfo() { City = "成都",Salary=2000f },
new CityInfo() { City = "武漢",Salary=2000f }
};
this.GridVIEw1.DataSource = s.Rank<CityInfo>((c, c1) => c.Salary.CompareTo(c1.Salary), "位次");
this.GridVIEw1.DataBind();
前台代碼
<ASP:GridView ID="GridVIEw1" runat="server" BackColor="White" Width="40%"
BorderColor="#67DB4A" BorderStyle="None" BorderWidth="1px" CellPadding="4">
<RowStyle BackColor="White" ForeColor="#003399" />
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
</ASP:GridVIEw>
顯示效果