Reputation: 1195
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
Upvotes: 1
Views: 1079
Reputation: 641
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.
Upvotes: 2