1

I'm trying to get the KeyField value from the FocusedRow in devexpress aspxGridview.

Following code i have so far

  • GridView

           <dx:ASPxGridView ID="ClientenSummary" runat="server" Width="700px" 
            OnSelectionChanged="ClientenSummary_SelectionChanged" EnableCallBacks="False">
    
            <ClientSideEvents FocusedRowChanged="function(s, e) 
    

    { OnGridFocusedRowChanged(); }" />

            <SettingsBehavior AllowSelectByRowClick="True" AllowSelectSingleRowOnly="True" ProcessSelectionChangedOnServer="True" />
            <SettingsPager PageSize="50">
            </SettingsPager>
            <Settings ShowFilterRow="True" ShowFilterRowMenu="True" />
        </dx:ASPxGridView>
    
  • JavaScript function in asp page markup

     <script language="javascript" type="text/javascript">
     function OnGridFocusedRowChanged() {
         ClientenSummary.GetRowValues(ClientenSummary.GetFocusedRowIndex(), 'ClassNR', OnGetRowValues);
     }
    
     function OnGetRowValues(values) {
         window.location = "../main.aspx?FocusedRowKeyField=" + values[0];
     }
    </script>
    
  • Backend C# code to resolve the query string

       protected void Page_Load(object sender, EventArgs e)
       {
        if (!string.IsNullOrEmpty(Request.Params["FocusedRowKeyField"]))
        {
            GetClientDetails(Request.Params["FocusedRowKeyField"]);
        }
    

The thing i can't to figure out is , why the QueryString isn't resolved. After some investigation on the interwebs i can't find a decent solution, so thats why I'm asking here. Hope someone can help

Nicolas Pierre
  • 1,174
  • 1
  • 21
  • 39
  • Where are you failing to resolve the query string? Is the failure happening on the page? Are you not seeing the value in your `Page_Load` codebehind? – 48klocs Jun 12 '12 at 19:46
  • @48klocs okay , i resolved the issue of bad databinding , but the querystring is still showing up empty – Nicolas Pierre Jun 12 '12 at 20:21
  • 1
    Use fiddler or firebug to verify what is being sent over the wire. Also, based on this question (http://stackoverflow.com/questions/3643041/setting-javascript-window-location) it seems like you should be using the window.location.href property. – Mark Peters Jun 12 '12 at 20:22
  • Okay it seems my `window.location.href` isnt get send through – Nicolas Pierre Jun 12 '12 at 20:38

1 Answers1

2

Ok first off you do not have AllowFocusedRow="true" in your SettingsBehavior for your grid. This is going to cause it to ignore any client side events for FocusRowChanged.

Secondly you need to tell the control whether you want to process the focused row changed event on the server or the client. I would recommend client and will post some code below. (DevExpress Documentation: http://documentation.devexpress.com/#AspNet/DevExpressWebASPxGridViewASPxGridView_FocusedRowChangedtopic)

Third you have ProcessSelectionChangedOnServer="True" which is going to fire the code for your ClientenSummary_SelectionChanged event. But you did not post this code and to be honest unless this is serving some specific function that you didn't post you don't need it for what you asked for.

Lastly I would recommend setting the client instance name of your grid, and the Key Fieldname. In my java code example I use "grid" and "ClassNR".

Java:

<script type="text/javascript">
function OnGridFocusedRowChanged() {
    grid.GetRowValues(grid.GetFocusedRowIndex(), 'ClassNR', OnGetRowValues);
}

function OnGetRowValues(ClassNR) {
    window.location.href = "../main.aspx?FocusedRowKeyField=" + ClassNR;
} 

Grid:

<dx:ASPxGridView ID="grid" ClientInstanceName="grid" runat="server" EnableCallBacks="false" KeyFieldName="ClassNR">

Settings:

<SettingsBehavior AllowSelectByRowClick="True" AllowSelectSingleRowOnly="True" ProcessFocusedRowChangedOnServer="false" AllowFocusedRow="true"  />

Client Side Event:

<ClientSideEvents FocusedRowChanged="function(s,e) { OnGridFocusedRowChanged(); }" /> 

This next bit is just to test the value, change it however you like. C#:

    protected void Page_Load(object sender, EventArgs e)
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(), "myScript", "<script language=JavaScript>alert(" + Request.Params["FocusedRowKeyField"] + ");</script>");  
    }

This is from a test application I set up for your question. It will update the browser address window (tested in IE9 only) with the FocusedRowKeyField when the focus row changes. It will also call the script in code behind which will pop up an alert with the value as well. The Page_Load event will be fired with each focus row change, you may want to modify that based on what you need this for.

dcreight
  • 641
  • 6
  • 18