Hello,
I'm using a RadGrid like a listbox, with a ClientSelectColumn so the selection of the items cam be handled client side. I have enabled client selection and multi row selection. These work fine if the checkbox is the item clicked. If I select multiple items by clicking on the checkbox in the ClientSelectColumn and then select another row by clicking outside of the checkbox, the row I clicked in is selected and the checkbox for that row is checked, but all of the previously checked items are now unchecked. Why are the previously selected rows unselected when the row itself is clicked?
Thanks,
Casey
I'm using a RadGrid like a listbox, with a ClientSelectColumn so the selection of the items cam be handled client side. I have enabled client selection and multi row selection. These work fine if the checkbox is the item clicked. If I select multiple items by clicking on the checkbox in the ClientSelectColumn and then select another row by clicking outside of the checkbox, the row I clicked in is selected and the checkbox for that row is checked, but all of the previously checked items are now unchecked. Why are the previously selected rows unselected when the row itself is clicked?
Thanks,
Casey
| <telerik:RadGrid ID="RadGrid2" runat="server" AutoGenerateColumns="False" |
| GridLines="None" ShowHeader="False" DataSourceID="SqlDataSource2" |
| Height="100px" AllowMultiRowSelection="True"> |
| <MasterTableView CellSpacing="-1" ShowHeadersWhenNoRecords="False"> |
| <Columns> |
| <telerik:GridClientSelectColumn UniqueName="column"> |
| </telerik:GridClientSelectColumn> |
| <telerik:GridBoundColumn UniqueName="column1" DataField="DESCRIPTION"></telerik:GridBoundColumn> |
| <telerik:GridBoundColumn UniqueName="column2" DataField="ID" Visible="false"></telerik:GridBoundColumn> |
| </Columns> |
| </MasterTableView> |
| <ClientSettings> |
| <Selecting AllowRowSelect="True" EnableDragToSelectRows="False" /> |
| <Scrolling AllowScroll="True" /> |
| </ClientSettings> |
| </telerik:RadGrid> |
7 Answers, 1 is accepted
0
Hello Casey,
Indeed this is the expected behavior and can be verified on this online demo of the product:
http://demos.telerik.com/aspnet-ajax/grid/examples/client/selecting/defaultcs.aspx
If you want to keep the previous selection, you will need to hold the Ctrl or Shift key when performing the sequence of action you described.
Best regards,
Sebastian
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Indeed this is the expected behavior and can be verified on this online demo of the product:
http://demos.telerik.com/aspnet-ajax/grid/examples/client/selecting/defaultcs.aspx
If you want to keep the previous selection, you will need to hold the Ctrl or Shift key when performing the sequence of action you described.
Best regards,
Sebastian
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Casey
Top achievements
Rank 1
answered on 28 Oct 2009, 03:22 PM
Sebastian,
Thanks for your reply.
I do have another question (which might lead to more questions). How do I access the value of the selected items on the clientside and store them into a hiddenfield's value? I need to store the value of the selected item in the value of a hidden field for an insert from a SqlDataSource at a later server-side event. I'm not having any luck with how I am trying to access the selected items. I tried storing them in the hidden field value, but it was always null, so now I'm just trying to prove that I am even accessing the values before trying to put them into the hidden field value. The alert shows: 'Null'
Any help would be appreciated.
Here is what I am using to try and show me that I am actually accessing the selected item(s) value(s): I modified the example from this: http://demos.telerik.com/aspnet-ajax/grid/examples/client/keys/defaultcs.aspx
Thanks for your reply.
I do have another question (which might lead to more questions). How do I access the value of the selected items on the clientside and store them into a hiddenfield's value? I need to store the value of the selected item in the value of a hidden field for an insert from a SqlDataSource at a later server-side event. I'm not having any luck with how I am trying to access the selected items. I tried storing them in the hidden field value, but it was always null, so now I'm just trying to prove that I am even accessing the values before trying to put them into the hidden field value. The alert shows: 'Null'
Any help would be appreciated.
Here is what I am using to try and show me that I am actually accessing the selected item(s) value(s): I modified the example from this: http://demos.telerik.com/aspnet-ajax/grid/examples/client/keys/defaultcs.aspx
| function GetSelectedItems() { |
| var storeField = $get("<%= HiddenField1.ClientID %>"); |
| var selectedItems = $find("<%= RadGrid2.MasterTableView.ClientID %>").get_dataItems()[0]; |
| var keyValues = selectedItems.getDataKeyValue("ID"); |
| alert(keyValues); |
| } |
| <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="GetSelectedItems(); return false;" /> |
0
Casey
Top achievements
Rank 1
answered on 28 Oct 2009, 06:21 PM
I am able to access the selected items after postback in another step, so I do not need to find the selected values via clientside anymore.
Sebastian,
In regards to that being the expected behavior, is it possible to no lose the selection of the other items if the row is clicked outside of the checkbox?
Thanks,
Casey
Sebastian,
In regards to that being the expected behavior, is it possible to no lose the selection of the other items if the row is clicked outside of the checkbox?
Thanks,
Casey
0
Hello Casey,
This is possible only when holding the Shift or Ctrl key from the keyboard or selecting the items using the checkbox from the GridClientSelectColumn. Alternatively, you can forbid selection when clicking rows using the approach with javascript from this code library entry.
Best regards,
Sebastian
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
This is possible only when holding the Shift or Ctrl key from the keyboard or selecting the items using the checkbox from the GridClientSelectColumn. Alternatively, you can forbid selection when clicking rows using the approach with javascript from this code library entry.
Best regards,
Sebastian
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Casey
Top achievements
Rank 1
answered on 29 Oct 2009, 12:14 PM
Thank you Sebastian, that worked. I had to change part of it because I was getting a javascript error that Control.addEventListener was null or not an object. I got rid of the error by changing the below.
Before Change:
After Change:
I do have another question now. I have the grid (RadGrid2) how I need it to be now. The client is able to select multiple rows only by clicking the checkboxes. Once they click a submit link a RadWindow opens, from the RadWindow they have to agree to a statement and click agree. On the click of the agree linkbutton in the RadWindow a script is executed on the parent window that originates an Ajax Request and the RadWindow is closed. The AjaxRequest iterates through RadGrid2 and gets the value of each selected item and then saves the value to a hidden field. After that an Insert statement is ran from a SqlDataSource. Once RadGrid2 has been iterated through, another grid (RadGrid1) is rebound to reflect the newly inserted rows. The problem I am having is that I am unable to unselect the rows in RadGrid2 after the SqlDataSource.Insert() is run. I stepper through the code and it looks like the items should be unselected, but when the page is done loading the items in RadGrid2 are still selected. Here is my code for the AjaxRequest. Please let me know if there is a way to unselect the rows in RadGrid2 at this point.
Thanks,
Casey
Before Change:
| function GridCreated() { |
| var grid = this; |
| //non-ie click event capture |
| //the event handler will get fired *before* the row click event |
| //and we use that to cache the current event object |
| if (grid.Control.addEventListener) |
| grid.Control.addEventListener("click", GridTableClick, true); |
| } |
After Change:
| function GridCreated() { |
| var grid = $find("<%= RadGrid2.ClientID %>"); |
| //non-ie click event capture |
| //the event handler will get fired *before* the row click event |
| //and we use that to cache the current event object |
| if (grid.Control.addEventListener) |
| grid.Control.addEventListener("click", GridTableClick, true); |
| } |
I do have another question now. I have the grid (RadGrid2) how I need it to be now. The client is able to select multiple rows only by clicking the checkboxes. Once they click a submit link a RadWindow opens, from the RadWindow they have to agree to a statement and click agree. On the click of the agree linkbutton in the RadWindow a script is executed on the parent window that originates an Ajax Request and the RadWindow is closed. The AjaxRequest iterates through RadGrid2 and gets the value of each selected item and then saves the value to a hidden field. After that an Insert statement is ran from a SqlDataSource. Once RadGrid2 has been iterated through, another grid (RadGrid1) is rebound to reflect the newly inserted rows. The problem I am having is that I am unable to unselect the rows in RadGrid2 after the SqlDataSource.Insert() is run. I stepper through the code and it looks like the items should be unselected, but when the page is done loading the items in RadGrid2 are still selected. Here is my code for the AjaxRequest. Please let me know if there is a way to unselect the rows in RadGrid2 at this point.
Thanks,
Casey
| protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e) |
| { |
| if (e.Argument.ToString() == "Rebind") |
| { |
| foreach (GridDataItem i in RadGrid2.Items) |
| { |
| if (i.Selected) |
| { |
| HiddenField1.Value = i["column2"].Text; |
| SqlDataSource3.Insert(); |
| i.Selected = false; |
| } |
| } |
| RadGrid1.Rebind(); |
| } |
| } |
0
Accepted
Shinu
Top achievements
Rank 2
answered on 29 Oct 2009, 01:11 PM
Hi Casey,
Try setting the AjaxSetting as shown below and see whether it helps.
ASPX:
-Shinu.
Try setting the AjaxSetting as shown below and see whether it helps.
ASPX:
| <asp:ScriptManager ID="ScriptManager1" runat="server"> |
| </asp:ScriptManager> |
| <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest"> |
| <AjaxSettings> |
| <telerik:AjaxSetting AjaxControlID="RadAjaxManager1"> |
| <UpdatedControls> |
| <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> |
| </UpdatedControls> |
| </telerik:AjaxSetting> |
| </AjaxSettings> |
| </telerik:RadAjaxManager> |
-Shinu.
0
Casey
Top achievements
Rank 1
answered on 29 Oct 2009, 01:15 PM
Shinu,
Adding the RadGrid to the AjaxManager worked, the items are now being unselected properly.
Thanks for the help!
Casey
Adding the RadGrid to the AjaxManager worked, the items are now being unselected properly.
Thanks for the help!
Casey