void
Page_Load(
object
sender, EventArgs e)
{
//测试数据
string[] myArr = new string[6];
myArr[0] = "地域";
myArr[1] = "地図";
myArr[2] = "路線";
myArr[3] = "道路交通";
myArr[4] = "電話帳";
myArr[5] = "自動車";
//没有排序
Gridview1.DataSource = myArr;
Gridview1.DataBind();
//简体中文排序
MyStringComparer myComp = new MyStringComparer(CompareInfo.GetCompareInfo("zh-CN"), CompareOptions.None);
Array.Sort(myArr, myComp);
Gridview2.DataSource = myArr;
Gridview2.DataBind();
//日语排序
myComp = new MyStringComparer(CompareInfo.GetCompareInfo("ja-JP"), CompareOptions.None);
Array.Sort(myArr, myComp);
Gridview3.DataSource = myArr;
Gridview3.DataBind();
}
private class MyStringComparer : IComparer
{
private CompareInfo myComp;
private CompareOptions myOptions = CompareOptions.None;
// Constructs a comparer using the specified CompareOptions.
public MyStringComparer(CompareInfo cmpi, CompareOptions options)
{
myComp = cmpi;
this.myOptions = options;
}
// Compares strings with the CompareOptions specified in the constructor.
public int Compare(Object a, Object b)
{
if (a == b) return 0;
if (a == null) return -1;
if (b == null) return 1;
string sa = a.ToString();
string sb = b.ToString();
if (sa != null && sb != null)
return myComp.Compare(sa, sb, myOptions);
throw new ArgumentException("a and b should be strings.");
}
}
{
//测试数据
string[] myArr = new string[6];
myArr[0] = "地域";
myArr[1] = "地図";
myArr[2] = "路線";
myArr[3] = "道路交通";
myArr[4] = "電話帳";
myArr[5] = "自動車";
//没有排序
Gridview1.DataSource = myArr;
Gridview1.DataBind();
//简体中文排序
MyStringComparer myComp = new MyStringComparer(CompareInfo.GetCompareInfo("zh-CN"), CompareOptions.None);
Array.Sort(myArr, myComp);
Gridview2.DataSource = myArr;
Gridview2.DataBind();
//日语排序
myComp = new MyStringComparer(CompareInfo.GetCompareInfo("ja-JP"), CompareOptions.None);
Array.Sort(myArr, myComp);
Gridview3.DataSource = myArr;
Gridview3.DataBind();
}
private class MyStringComparer : IComparer
{
private CompareInfo myComp;
private CompareOptions myOptions = CompareOptions.None;
// Constructs a comparer using the specified CompareOptions.
public MyStringComparer(CompareInfo cmpi, CompareOptions options)
{
myComp = cmpi;
this.myOptions = options;
}
// Compares strings with the CompareOptions specified in the constructor.
public int Compare(Object a, Object b)
{
if (a == b) return 0;
if (a == null) return -1;
if (b == null) return 1;
string sa = a.ToString();
string sb = b.ToString();
if (sa != null && sb != null)
return myComp.Compare(sa, sb, myOptions);
throw new ArgumentException("a and b should be strings.");
}
}