如何排序Telerik RadGrid,除了前两行?我试图在SortCommand事件上实现它。
采取两个表,在第一个我把前两行和第二个表我有除前两个之外的所有行。然后我只对第二个表进行排序,最后合并两个并在GridView上加载数据。
var dtManager = GetGridData(); // To get data to load on grid
string sortOrder = Convert.ToString(Session["SortOrder"]);
var dtManagerTop2 = dtManager.Clone();
var dtManagerExceptTop2 = dtManager.Clone();
for (int rowIndex = 0; rowIndex < dtManager.Rows.Count; rowIndex++) {
if (rowIndex < 2) {
dtManagerTop2.ImportRow(dtManager.Rows[rowIndex]);
} else {
dtManagerExceptTop2.ImportRow(dtManager.Rows[rowIndex]);
}
}
var dvManager = dtManagerExceptTop2.DefaultView;
string sortBy = sortByText == string.Empty ? "Name" : sortByText;
dvManager.Sort = sortBy + " " + sortOrder;
var dtNew = dvManager.ToTable();
dtManagerTop2.Merge(dtNew);
dsGrid.DataSource = dtManagerTop2;
if (Convert.ToString(Session["SortOrder"]) == "desc") {
Session["SortOrder"] = "asc";
} else {
Session["SortOrder"] = "desc";
}
答案 0 :(得分:0)
代码背后:
Grid.Columns.FindByUniqueName("Type").SortExpression = string.Empty;
或来自HTML:
<Columns>
<tr:GridBoundColumn DataField="field"
HeaderText="Description"
AllowSorting="false" />
</Columns>