tags:

views:

1461

answers:

3

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.
    }
}
A: 

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

Wael Dalloul
Well i can get values if i bind grid at page_load. So my problem is not about getting them. I'm not sure how but it can't get the values loaded only after page index changed. Also if i change page index without selecting any item from first page it works at the new page.And yes it supports multi selection.
Ahmet Kakıcı
Wael i checked the other solutions and i think it will work. But it's the easiest way to get the values with GetSelectedFieldValues. But i can't find why it doesn't work while binding grid at pageindexchange event.
Ahmet Kakıcı
A: 

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.

AGoodDisplayName
Turning callbacks maybe a solution but not a good for me because it's a GIS project and i have a map at the same page. So if i post back grid for pager, an another request to map server will be sent. I know there may be some workarounds for this issue but it seems a bit wierd that we can't use grid like that way.
Ahmet Kakıcı
A: 

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).

Beresta
As for the PageIndexChanged binding - this event raised only on the corresponsing callback (when you change page). On the GetSelectedFieldValues callback this event doesn't get fired.
Beresta