with only one gridbutton I don't have problem.
I use event:
Protected Sub RadGrid1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid1.SelectedIndexChanged
But with something like this (2 or moore buttons):
<radG:GridButtonColumn CommandName="Diana" HeaderText="Dettagli" Text="[Diana]" UniqueName="Diana">
</radG:GridButtonColumn>
<radG:GridButtonColumn CommandName="Sara" Text="[Sara]" UniqueName="Sara">
</radG:GridButtonColumn>
on
Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.WebControls.GridCommandEventArgs) Handles RadGrid1.ItemCommand
Dim item As GridDataItem
MyCmd = e.CommandName
Select Case MyCmd
Case "Diana"
Case "Sara"
...
works
but
item = RadGrid1.SelectedItems.Item(0)
myKey = item("FId").Text
say me that I don't have selected item.
someone can help me?
Thanks
RRE
15 Answers, 1 is accepted

Try the following code snippet to access the selected item in the ItemCommand event.
VB:
Protected Sub RadGrid1_ItemCommand(source As Object, e As GridCommandEventArgs) |
If e.CommandName = "Diana" Then |
For Each selecteditem As GridDataItem In RadGrid1.SelectedItems |
Dim strtxt As String = selecteditem("FId").Text |
Next |
End If |
End Sub |
Thanks
Shinu.

I done it, I simply click on one of 2 gidbutton on my
for each...
I don't have selected items!
If FIRST I click on row and then I click on a gridbutton I have an item selected.
probably I have to set something on grid ?
thanks
Renato
Please try to set EnablePostBackOnRowClick property to true:
<ClientSettings EnablePostBackOnRowClick="true"></ClientSettings> |
Regards,
Daniel
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

this is my ClientSettings
<ClientSettings AllowColumnsReorder="True" EnablePostBackOnRowClick="true">
<Selecting AllowRowSelect="True" />
</ClientSettings>
but on my RadGrid1_ItemCommand
I don't receive selected items.
Simply if I try
RadGrid1.SelectedItems.Count
the result is 0
Greetings
Renato
Please examine the sample website I created for your convenience and let us know whether it works as expected.
Regards,
Daniel
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

thanks for support.
I studied your example. It works!
If I understand you suggest to use simple columns and track the click with a generic "RowClick" name that appears on ItemCommand event. This only if on my grid I don't have GridButtonColumn.
The row selection with GridButtonColumn works only with one button on a grid.
Is tat correct?
With Thanks
Renato
There is no dependency between the number of your GridButtonColumns and the discussed functionality.
I modified the example to show the same message on SelectionChanged event. I also added a couple of columns in order to test the depicted behavior. Unfortunately I'm still unable to reproduce it. Am I missing something?
Kind regards,
Daniel
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

It works fine when I call the SelectedIndexChanged handler from Page_Load, after calling SelectedIndexes.Add(new int[]{0}) to make sure there is a selection. However, when it's called from SelectedIndexChanged, there is no selection. Also, when SelectedIndexChanged fires and the SelectedX attributes are examined from Page_Load, there is still no selection.
Finally, as soon as the callback completes, the selection highlighting disappears from the screen, so it is visible only as long as it takes to do the callback.
I have tried removing options from the grid, in case one of them made a difference, and also tried using ItemCommand, always with the same result.
Your sample program works fine for me.
Here is my code:
<
telerik:RadGrid ID="GridOffice" runat="server" AutoGenerateColumns="False" GridLines="None" AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
AllowAutomaticUpdates="True" onrowdrop="GridOffice_RowDrop" AutoGenerateDeleteColumn="True" onitemcommand="GridOffice_ItemCommand"
>
<MasterTableView CommandItemDisplay="Bottom" EditMode="PopUp" DataKeyNames="StateKey,OfficeSeq">
<Columns>
<telerik:GridBoundColumn DataField="Text" EmptyDataText="&nbsp;" HeaderText="Office" UniqueName="Office" />
<telerik:GridEditCommandColumn />
</Columns>
<EditFormSettings>
<EditColumn UniqueName="EditCol" HeaderText="Add" />
</EditFormSettings>
</MasterTableView>
<ClientSettings AllowRowsDragDrop="True" EnablePostBackOnRowClick><Selecting AllowRowSelect="True" /></ClientSettings>
<FilterMenu EnableTheming="True"><CollapseAnimation Type="OutQuint" Duration="200"/></FilterMenu>
</
telerik:RadGrid>
protected void GridOffice_ItemCommand(object source, GridCommandEventArgs e) {
if (GridOffice.SelectedIndexes.Count < 1) return;
string index = GridOffice.SelectedIndexes[0];
GridRace.DataSource =
from r in mDc.Race
where r.StateKey == GridOffice.SelectedValues["StateKey"] & r.OfficeSeq == Convert.ToInt16(GridOffice.SelectedValues["OfficeSeq"])
select r;
}

The only problem is that when I reorder rows using drag & drop, the DestDataItems in the RowDrop handler are all empty if I don't databind in Page_Load. NeedDataSource is not being called, and it's too late if I do it inside the RowDrop handler.
Anyone have suggestions?

your example works because you add column on grid, not buttons.
You have to add at least 2 GridButtonColumn on grid to see the problem.
Thanks
Renato
I tried to recreate your case but without avail. Please test the attached example and let me know whether it's working as expected.
Best regards,
Daniel
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Could you please modify the project I previously attached and then attach it to a formal support ticket in order to be debugged locally.
Thank you for your cooperation.
Kind regards,
Daniel
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

The problem is that to select a Button on a grid you have - only the first time - to select a row. Then ir will works.
greetings

greetings
Renato
