gpt4 book ai didi

c# - DevExpress MVC GridView

转载 作者:行者123 更新时间:2023-11-30 22:58:53 25 4
gpt4 key购买 nike

大家好我正在尝试使用此代码在 GridView 上添加一个额外的列。但是当我运行它时。我无法单击 GridView 上的按钮。知道我做错了什么。谢谢

        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");

更新:我通过网络开发人员工具在网络上发现了错误,但我不知道如何修复它 Error button hover

最佳答案

听起来问题源自 s,它分配给此 block 上的按钮发送器而不是 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());

注意事项:

1) 如果要获取行索引,使用c.VisibleIndex

2) 对于跨浏览器问题,我更喜欢 window.location 而不是 document.location 提供 here .

相关问题:GridView - How to define Button inside grid

关于c# - DevExpress MVC GridView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52660648/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com