I'm using the ASP.NET RadGrid for AJAX and I have an asp LinkButton in my grid's CommandItemTemplate.
I am trying to set the linkbutton's Visible property to True, when a user selects a row in the grid. When no row is selected, the control should not be visible.
<CommandItemTemplate>
<asp:LinkButton ID="CopyJobFunctionButton" runat="server" CommandName="CopyJobFunction" Visible="<%# GridViewLeft.SelectedItems.Count > 0 %>"></asp:LinkButton>
</CommandItemTemplate>
I have tried to set the Visible property to the statement shown above, thinking that as soon as an item is selected, the SelectedItems.Count will be greater than 0 and that will return True.
That is not working. The LinkButton does NOT show up when a row is selected.
What can I be doing wrong? Or how else can I achieve this?
Thanks,
Brent
8 Answers, 1 is accepted
How the grid rows are selected in your case? Server-side or client-side?
Greetings,
Vlad
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
I'm not an expert so I'm not sure how to answer that.
I do know that I have additional linkbuttons in that very same CommandItemTemplate (I omitted them from the forum post) that are also setting their Visible property in this similar manner, and they work.
For instance, in that same grid, the following successfully sets the visibility of our Add New linkbutton, based on whether the grid is in edit / insert mode or not:
<
asp:LinkButton ID="InsertNewLinkButton" runat="server" CommandName="InitInsert" Visible="<%# !GridViewLeft.MasterTableView.IsItemInserted && GridViewLeft.EditIndexes.Count == 0 %>"OnClientClick="return SystemWorks.ConfigureFunctions.onRowSelecting();"></asp:LinkButton>
So, based on that, I would have assumed that my other example based on SelectedItems.Count would have worked.
Can you ask your question in another way, or tell me how to answer it please?
Thanks,
Brent
I assume that you enabled client-side selection (ClientSettings -> Selecting -> AllowRowSelect = true) for your grid because with server-side selection the button's visibility should be changed accordingly. Furthermore, you specified that other hidden buttons in the command item are displayed as expected on edit/insert operation which triggers postback or ajax request.
Therefore, my suggestion would be to trigger postback or ajax request (if you ajaxified the grid through RadAjaxManager or RadAjaxPanel) by specifying ClientSettings -> EnablePostBackOnRowClick = true for the grid instance. Here is an example which illustrates how this approach can be utilized to filter related records in a second grid:
http://demos.telerik.com/ASPNET/Prometheus/Grid/Examples/Programming/SelectedValue/DefaultCS.aspx
Kind regards,
Stephen
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
My question and issue is not about "how to trigger the postback or ajax request". That is occurring without a problem.
My issue is that even though my ajax postbacks are working, and other controls in the page are being updated correctly, my link button that uses the following for the Visible property in the aspx page, isn't working:
Visible="<%# GridViewLeft.SelectedItems.Count > 0 %>
">
In the same CommandTemplate that I have this linkbutton, I also have another linkbutton where I'm successfully setting the Visible property using the same type of logic, but am using
<%# !GridViewLeft.MasterTableView.IsItemInserted && GridViewLeft.EditIndexes.Count == 0 %>
So again, it isn't a question of my postback / ajax not working. It is a question of: Why isn't SelectedItems.Count returning what I expect in this scenario?
Thanks,
Brent
By utilizing the suggestion from my previous reply I think that you will attain the functionality for the button in the command item you are after. Try it out and let me know how it goes.
Regards,
Stephen
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
I am already setting EnablePostBackOnRowClick = true on that grid, and as I specified, all that is working. An ajax postback is occurring, and server code is running, and everything is working except the one thing I keep mentioning...
So, you still aren't answering my exact question, but never mind. I'll figure it out.
Thanks,
Brent
I am able to get the count on the server side - SelectedIndexChanged event handler BUT I have a GridClientSelectColumn and when I click on the "checkall" checkbox at the top of the column there is no postback...
Is there either a way of getting the radgrid.ItemsSelected.Count in an event that fires any time something in the GridClientSelectColumn is clicked (including the check all checkbox in header) on the client side, or force a postback on the checkall check box in the header?
When you click the checkbox in the header of the GridClientSelectColumn or a template column with asp CheckBox in the header, all rows in the grid (or on the current page if paging is enabled) will become selected. Hence you will know that the count of the selected items will be equal to the <GridInstance>.MasterTableView.Items.Count.
To display the count of the selected items you will need to intercept either the onclick client event of the GridClientSelectColumn header checkbox or the OnCheckedChanged server event of the asp CheckBox in the template column header (see the demo linked above for details).
Best regards,
Sebastian
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.