我想选择一个DevExpress MVC GridView的特定行,其中包含一个keyvalue。我在gridview中尝试了以下代码。
settings.DataBound = (sender, e) =>
{
MVCxGridView grid = (MVCxGridView)sender;
grid.PageIndex = 5;
};
settings.PreRender = (sender, e) =>
{
MVCxGridView grid = (MVCxGridView)sender;
grid.FocusedRowIndex = grid.FindVisibleIndexByKeyValue(35);
};
我希望得到的是突出显示包含keyvalue 35的第5页的行。上面的代码对我的行选择不起作用。
请有人建议解决方案。
提前致谢。
答案 0 :(得分:3)
行选择:
您可以通过以下方式通过 ASPxGridView.Selection.SetSelectionByKey 方法选择所需的DataRow:
C#:
settings.PreRender = (sender, e) => {
ASPxGridView gridView = (ASPxGridView)sender;
object keyValue = 35;
gridView.Selection.SetSelectionByKey(keyValue, true);
};
VB.NET:
settings.PreRender = _
Sub(sender, e)
Dim gridView As ASPxGridView = CType(sender, ASPxGridView)
Dim keyValue As Object = 35
gridView.Selection.SetSelectionByKey(keyValue, True)
End Sub
您可以在DevExpress支持库中找到类似的实现:
http://www.devexpress.com/Support/Center/p/Q317380.aspx
聚焦行:
C#:
settings.PreRender = (sender, e) => {
ASPxGridView gridView = (ASPxGridView)sender;
object keyValue = 35;
gridView.FocusedRowIndex = gridView.FindVisibleIndexByKeyValue(keyValue);
};
VB.NET:
settings.PreRender = _
Sub(sender, e)
Dim gridView As ASPxGridView = CType(sender, ASPxGridView)
Dim keyValue As Object = 35
gridView.FocusedRowIndex = gridView.FindVisibleIndexByKeyValue(keyValue)
End Sub
答案 1 :(得分:2)
我得到了一个使用客户端javascript函数的解决方案。
settings.PreRender = (sender, e) =>
{
MVCxGridView grid = (MVCxGridView)sender;
var selected = 35;
if (Convert.ToInt64(selected) > 0)
{
int index = grid.FindVisibleIndexByKeyValue(selected );
grid.PageIndex = index / grid.SettingsPager.PageSize;
grid.ClientSideEvents.Init = @"function(s, e)
{ s.SetFocusedRowIndex(" + index + ");}";
}
};