Devexpress ASPxGridView GetSelectedFieldValues 无法获取值

发布于 2024-09-03 01:02:19 字数 1263 浏览 3 评论 0原文

我正在使用带有分页功能的网格视图。我的网格有一个命令列,并且 ShowSelectCheckbox 设置为 true。我在 Page_Load 事件中使用条件 [ if (!IsCallback) ] 将 DataTable 绑定到网格。

因此,当我更改页面索引时,数据会丢失。之后,我将绑定代码写入网格的 PageIndexChanged 事件。现在它就像魅力一样发挥作用。

但是,当 SelectionChanged 事件发生时,GetSelectedFieldValues 仅在首页起作用。

例如,当我在第一页选择一行时,它会获取我想要的字段值。但是当我更改页面索引时 GetSelectedField 无法获取字段值。它会提醒空文本。

如果我在第二页索引处选择一行,它也适用于该页面,但是当我更改页面索引时,它会再次损坏。

顺便说一句,当我在没有 !IsCallback 条件的情况下在 PageLoad 事件中绑定网格时,它可以工作,但由于其他控件,我无法在 Page_Load 事件中绑定它必须要更改查询等数据。

这是我的 javascript 函数,它会提醒选定的值

<ClientSideEvents SelectionChanged="function(s, e) {
    grid.GetSelectedFieldValues('SDNO;SANTRAL',alert);
}" />

和页面索引更改事件

protected void myGrid_PageIndexChanged(object sender, EventArgs e)
    {
        myGridDataSource = dtable; //dtable is static, i also used BindThat function here too. But no way out.
        myGridDataBind();
    }

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsCallback)
    {
        BindThat(); // Fetch data from db, create dtable and bind it to grid.
    }
}

I'm using a gridview with paging. My grid has a command column and ShowSelectCheckbox is set to true. I bind DataTable to grid at Page_Load event with the condition [ if (!IsCallback) ].

So when i change page index data is lost. After that i wrote bind code to grid's PageIndexChanged event. Now it works like charm.

But GetSelectedFieldValues works only at first page when SelectionChanged event occurs.

In example when i select a row at first page it gets the field values that i want. But when i change pageindex GetSelectedField cannot get the field values. It alerts empty text.

If i select a row at second page index it works at that page too, but when i change page index it's broken again.

BTW it works when i bind the grid at PageLoad event without !IsCallback condition but i can't bind it at Page_Load event because of other controls must have to change the query and so data.

Here goes my javascript function which alerts selected values

<ClientSideEvents SelectionChanged="function(s, e) {
    grid.GetSelectedFieldValues('SDNO;SANTRAL',alert);
}" />

And page index changed event

protected void myGrid_PageIndexChanged(object sender, EventArgs e)
    {
        myGridDataSource = dtable; //dtable is static, i also used BindThat function here too. But no way out.
        myGridDataBind();
    }

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsCallback)
    {
        BindThat(); // Fetch data from db, create dtable and bind it to grid.
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

说不完的你爱 2024-09-10 01:02:19

我认为这不是从客户端网格获取值的正确方法,请检查以下链接:
http://www.devexpress.com/Support/Center/p/Q94237。 aspx

[JScript]
function Button1_onclick() {
    ASPxGridView1.GetSelectedFieldValues("CategoryID;CategoryName", OnGetSelectedFieldValues);
}

function OnGetSelectedFieldValues(result) {
    for(var i = 0; i < result.length; i ++)
        for(var j = 0; j <result[i].length; j++) {
            alert(result[i][j]);
        }
} 

问:你们的grid支持多选吗?

编辑1
另请检查以下示例:

如何使用 GetSelectedFieldValues 方法获取多个值一次列

如何从服务器

I think this is not the correct way to get the values from the grid at client side, check the following link:
http://www.devexpress.com/Support/Center/p/Q94237.aspx

[JScript]
function Button1_onclick() {
    ASPxGridView1.GetSelectedFieldValues("CategoryID;CategoryName", OnGetSelectedFieldValues);
}

function OnGetSelectedFieldValues(result) {
    for(var i = 0; i < result.length; i ++)
        for(var j = 0; j <result[i].length; j++) {
            alert(result[i][j]);
        }
} 

Question: is your grid support multiple selection?

Edit1:
Check the following Examples as well:

How to use a GetSelectedFieldValues method to obtain values of several columns at once

How to get the values of the selected record from the server

噩梦成真你也成魔 2024-09-10 01:02:19

ASPxClientGridView.GetSelectedFieldValues 方法发送回调以获取指定的数据。因此,如果您没有在此回调的服务器端绑定 ASPxGridView(实际上您没有绑定 - 由于条件 [ if (!IsCallback) ]),网格将无法返回数据。

顺便说一句,这适用于当前页面,因为 ASPxGridView 正在缓存当前页面的数据(请参阅 EnableRowsCache 属性定义)。

ASPxClientGridView.GetSelectedFieldValues method send a callback to get the specified data. So, if you don't bind the ASPxGridView at the server side on this callback (and you actually don't - because of condition [ if (!IsCallback) ]) grid cannot return the data.

BTW, this works on the currect page because ASPxGridView is caching the data for the current page (see EnableRowsCache property definition).

静谧 2024-09-10 01:02:19

您可能想尝试关闭网格的回调。我发现这解决了我在网格方面遇到的一些问题。我不确定这是否有效,但可能值得一试。

<dxwgv:ASPxGridView ID="xgvMyGrid" runat="server" AutoGenerateColumns="False"
 EnableCallBacks="False">

注意...虽然网格应该仍然可以正常工作,但这可能会影响您可能已经存在的其他代码。

You may want to try turning off callbacks for the grid. I've found that this solves some issues that I run into with the grid. I am not sure this will work, but it may be worth a shot.

<dxwgv:ASPxGridView ID="xgvMyGrid" runat="server" AutoGenerateColumns="False"
 EnableCallBacks="False">

Note...Although the grid should still work just fine, this may affect other code you may already have in place.

乖不如嘢 2024-09-10 01:02:19

另请检查 Grid 的 KeyFieldName。如果此信息未指定或不正确,您可能也无法检索 GetSelectedFieldValues 客户端事件中的值。

And also please check the KeyFieldName of Grid. If this information is not specified or not correct you may also not be able to retrieve the values in GetSelectedFieldValues client event.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文