大家好 我正在尝试使用此代码在网格视图上添加额外的列。但是当我运行它时。我无法单击网格视图上的按钮。知道我在做什么错。谢谢
settings.Columns.Add(column =>
{
column.FieldName = "Unbound";
column.Caption = "Action";
column.UnboundType = DevExpress.Data.UnboundColumnType.Object
column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.True;
column.ReadOnly = false;
column.SetDataItemTemplateContent((c) =>
{
Html.DevExpress().Button(b =>
{
b.Name = "btnVE" + c.KeyValue;
b.Text = "V/E";
b.ClientSideEvents.Click =
"function(s, e) { document.location='" + DevExpressHelper.GetUrl(new { Controller = "ViewPrincipal", Action = "EditRecord" })
+ "?key=' + s.GetRowKey(e.visibleIndex); }";
}).GetHtml();
});
});
settings.Columns.Add("Id");
settings.Columns.Add("Code");
settings.Columns.Add("CompanyId");
settings.Columns.Add("Description");
settings.Columns.Add("ContactPerson");
settings.Columns.Add("TelNo");
settings.Columns.Add("Notes");
更新: 我通过Web开发人员工具在Web上发现了错误,但我不知道如何解决 Error button hover
答案 0 :(得分:2)
类似问题的声音源自s
,该GridView
分配给此块中的按钮发送器,而不是Html.DevExpress().Button(b =>
{
b.Name = "btnVE" + c.KeyValue;
b.Text = "V/E";
b.ClientSideEvents.Click =
"function(s, e) { document.location='" + DevExpressHelper.GetUrl(new { Controller = "ViewPrincipal", Action = "EditRecord" })
+ "?key=' + s.GetRowKey(e.visibleIndex); }"; // ==> 's' refers to button object as sender
}).GetHtml();
行:
GridViewDataItemTemplateContainer
您应该使用KeyValue
对象来获取相应行的GridViewBaseRowTemplateContainer
属性,该属性从column.SetDataItemTemplateContent((c) =>
{
Html.DevExpress().Button(b =>
{
b.Name = "btnVE" + c.KeyValue;
b.Text = "V/E";
b.UseSubmitBehavior = false; // prevent default submit action
b.EnableClientSideAPI = true; // add this line if not sure
b.ClientSideEvents.Click =
"function(s, e) { window.location = '" + DevExpressHelper.GetUrl(new { Controller = "ViewPrincipal", Action = "EditRecord" })
+ "?key=" + c.KeyValue.ToString() + "'; }";
}).GetHtml();
});
返回整数值:
string.Format()
或使用更易于阅读的b.ClientSideEvents.Click = string.Format("function(s, e) {{ window.location = '{0}?key={1}'; }}",
DevExpressHelper.GetUrl(new { Controller = "ViewPrincipal", Action = "EditRecord" }),
c.KeyValue.ToString());
:
c.VisibleIndex
注释:
1)如果要获取行索引,请使用window.location
。
2)出于跨浏览器的考虑,我更喜欢here提供document.location
而不是/// <sumary>Check if file exists with timeout</sumary>
/// <param name="fileInfo">source</param>
/// <param name="millisecondsTimeout">The number of milliseconds to wait,
/// or <see cref="System.Threading.Timeout.Infinite"/> (-1) to wait indefinitely.</param>
/// <returns>Gets a value indicating whether a file exists.</returns>
public static bool Exists(this FileInfo fileInfo, int millisecondsTimeout)
{
var task = new Task<bool>(() => fileInfo.Exists);
task.Start();
return task.Wait(millisecondsTimeout) && task.Result;
}
。
答案 1 :(得分:0)
发现了问题。显然,应在创建网格视图之前将其放置在视图的前面。但我当时认为这应该是JScript。它应该异步运行。哦,只要有效即可。感谢您的帮助@tetsuya
@Html.DevExpress().GetStyleSheets(
new StyleSheet { ExtensionSuite = ExtensionSuite.NavigationAndLayout },
new StyleSheet { ExtensionSuite = ExtensionSuite.Editors, ExtensionType = ExtensionType.Button },
new StyleSheet { ExtensionSuite = ExtensionSuite.GridView }
)
@Html.DevExpress().GetScripts(
new Script { ExtensionSuite = ExtensionSuite.NavigationAndLayout },
new Script { ExtensionSuite = ExtensionSuite.Editors, ExtensionType = ExtensionType.Button },
new Script { ExtensionSuite = ExtensionSuite.GridView }
)