Is it possible to detect a server-side event when the user clicks on a datagrid row regardless of wherever on the row area the
click happens?
I simply want to take the user to a separate .aspx page when the click occurs and pass the row ID / primary key to the second page.
Thanks
I simply want to take the user to a separate .aspx page when the click occurs and pass the row ID / primary key to the second page.
Thanks
4 Answers, 1 is accepted
0
Schlurk
Top achievements
Rank 2
answered on 29 Oct 2009, 09:40 PM
You could always subscribe to the OnRowClick client-side event and open the page with the following function:
Although for passing your ID/Key you would probably have to use hidden fields. You could, alternatively, just subscribe to the OnRowClick event and then set hidden fields equal to the row ID / primary keys and then open the page through the code-behind instead of javascript.
| function openWindow(pageName) |
| { |
| window.open(pageName); |
| } |
Although for passing your ID/Key you would probably have to use hidden fields. You could, alternatively, just subscribe to the OnRowClick event and then set hidden fields equal to the row ID / primary keys and then open the page through the code-behind instead of javascript.
0
LG
Top achievements
Rank 2
answered on 29 Oct 2009, 10:27 PM
Thanks for your reply but I'm trying to avoid the client-side approach, if I can.
With the following properties the RadGrid is able to highlight the entire row when I click on it. Why it doesn't trigger a server-side event?
With the following properties the RadGrid is able to highlight the entire row when I click on it. Why it doesn't trigger a server-side event?
| <ClientSettings> |
| <Selecting AllowRowSelect="True" /> |
| </ClientSettings> |
| <SelectedItemStyle BackColor="Fuchsia" BorderColor="Purple" BorderStyle="Dashed" BorderWidth="1px" /> |
It seems like we are half way there.
0
Princy
Top achievements
Rank 2
answered on 30 Oct 2009, 06:20 AM
Hi RJ,
You can set the EnablePostBackOnRowClick property to true to trigger a postback on clicking a row .
| <ClientSettings EnablePostBackOnRowClick="true"> |
| <Selecting AllowRowSelect="true" /> |
| </ClientSettings> |
You can check for this in the ItemCommand
| protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) |
| { |
| if (e.CommandName == "RowClick") |
| { |
| } |
| } |
Thanks,
Princy
0
LG
Top achievements
Rank 2
answered on 30 Oct 2009, 04:43 PM
Thanks, Princy!! This is exactly what I was looking for.
Here is the complete solution for others:
RJ
Here is the complete solution for others:
| <telerik:RadGrid ShowGroupPanel="false" AutoGenerateColumns="false" |
| ID="RadGrid1" runat="server" AllowMultiRowSelection="false" |
| Height="578px" Width="99%" |
| ShowFooter="False" onitemcommand="RadGrid1_ItemCommand"> |
| <PagerStyle Mode="NumericPages" /> |
| <MasterTableView TableLayout="Fixed"> |
| <Columns> |
| <telerik:GridBoundColumn HeaderText="RowID" DataField="RowID" UniqueName="RowID" Visible="false"> |
| </telerik:GridBoundColumn> |
| ..... |
| </Columns> |
| </MasterTableView> |
| <ClientSettings EnablePostBackOnRowClick="true"> |
| <Scrolling AllowScroll="true" UseStaticHeaders="true"></Scrolling> |
| <Selecting AllowRowSelect="True" /> |
| </ClientSettings> |
| </telerik:RadGrid> |
| protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) |
| { |
| switch (e.CommandName) |
| { |
| case "RowClick": |
| GridDataItem dataItem = e.Item as GridDataItem; |
| Response.Redirect("~/Detail.aspx?id=" + dataItem["ColumnUniqueName"].Text); |
| break; |
| default: |
| break; |
| } |
| } |
RJ