This is a migrated thread and some comments may be shown as answers.

how to know the row selected clicking on 2 gridbutton ?

15 Answers 270 Views
Grid
This is a migrated thread and some comments may be shown as answers.
RRE
Top achievements
Rank 2
Iron
RRE asked on 14 Oct 2008, 05:24 PM
Hi,

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

Sort by
0
Shinu
Top achievements
Rank 2
answered on 15 Oct 2008, 04:24 AM
Hi Renato,

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.
0
RRE
Top achievements
Rank 2
Iron
answered on 16 Oct 2008, 04:28 PM
Thanks,

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
0
Daniel
Telerik team
answered on 16 Oct 2008, 05:08 PM
Hello 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.
0
RRE
Top achievements
Rank 2
Iron
answered on 17 Oct 2008, 08:10 AM
Dear Daniel,

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


0
Daniel
Telerik team
answered on 17 Oct 2008, 06:07 PM
Hello 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.
0
RRE
Top achievements
Rank 2
Iron
answered on 20 Oct 2008, 04:32 PM
Dear Daniel,

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
0
Daniel
Telerik team
answered on 22 Oct 2008, 02:22 PM
Hello 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.
0
Jim
Top achievements
Rank 1
answered on 26 Oct 2008, 11:23 PM
I have the same problem.  In the handler for SelectedIndexChanged, the grid reports that it has no selection.  (The count is 0 on all the SelectedX attributes.  It doesn't seem to matter how many buttons there are, but instead seems to be associated with the use of SelectedIndexChanged, rather than ItemCommand.

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="&amp;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;

 

}

0
Jim
Top achievements
Rank 1
answered on 27 Oct 2008, 12:00 AM
I figured out my problem.  I was databinding that grid in Page_Load, even on postbacks.  Once I remove that, it works fine.

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_LoadNeedDataSource is not being called, and it's too late if I do it inside the RowDrop handler.

Anyone have suggestions?
0
RRE
Top achievements
Rank 2
Iron
answered on 27 Oct 2008, 05:53 AM
Dear Daniel,

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

0
Daniel
Telerik team
answered on 29 Oct 2008, 12:29 PM
Hello James,

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.
0
Daniel
Telerik team
answered on 29 Oct 2008, 12:35 PM
Hello Renato,

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.
0
RRE
Top achievements
Rank 2
Iron
answered on 29 Oct 2008, 04:33 PM
ok I will do it.

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
0
RRE
Top achievements
Rank 2
Iron
answered on 29 Oct 2008, 05:54 PM
My ticket is 170694

greetings

Renato
0
Jim
Top achievements
Rank 1
answered on 31 Oct 2008, 02:26 AM
It's working for me now.
Tags
Grid
Asked by
RRE
Top achievements
Rank 2
Iron
Answers by
Shinu
Top achievements
Rank 2
RRE
Top achievements
Rank 2
Iron
Daniel
Telerik team
Jim
Top achievements
Rank 1
Share this question
or