I am using ASP.Net with VB to display records in a grid view. In a normal ASP GridView, I can simply handle SelectedIndexChanged Event from code behind like this:
Sub mySub(ByVal sender as Object, ByVal e As EventArgs)
Handles GridView1.SelectedIndexChanged
Dim id as String = GridView1.SelectedRow.Item(0).ToString
Response.Redirect("Customer.aspx?ID=" & id) 'Or Whatever
End Sub
Now I am trying to do the same but with ASPxGridView that comes with DevExpress. Obviosly, there is no built in Event that can be handled directly from code behind. I have to go through client click with javascript, which I don't mind to but all my attempts to pass the click event from the client to the server code behind failed.
Here is my ASP page
<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False"
KeyFieldName="id" Width="550px" OnSelectionChanged="row_selected" >
<SettingsBehavior AllowFocusedRow="True" />
<SettingsText Title="Customers" />
<Columns>
<dx:GridViewDataTextColumn FieldName="id" ReadOnly="True" VisibleIndex="1">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="Name" VisibleIndex="2">
</dx:GridViewDataTextColumn>
</Columns>
<Settings ShowTitlePanel="True" />
<ClientSideEvents FocusedRowChanged="function(s, e) {
row_selected();
}" />
</dx:ASPxGridView>
And here is my code behind (Which never gets called)
Sub row_selected()
Dim id as String = ASPxGridView1.SelectedRow.Item(0).ToString
Response.Redirect("Customers.aspx?ID=" & id)
End Sub
How can I call a function from code behind by clicking on a row on ASPxGridView row?
Try this:
1. Set ASPxGridView1.SettingsBehavior.ProcessFocusedRowChangedOnServer to true.
2. Handle server side FocusedRowChanged event