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

SelectedValue of 1 Row when multiple rows are selected...

1 Answer 52 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mark baer
Top achievements
Rank 1
mark baer asked on 10 Jun 2011, 10:24 PM
I have a RadGrid where multiple rows can be selected.  But whatever 1 Row the user clicks on, that is the one I want to show the details for.  Currently, if I click on a Row that has NOT been selected already, I can get the ID using RadGrid.SelectedValue.  But if I click on a Row that has been ALREADY selected, I get the ID of the Row that was selected BEFORE the currently selected Row.  Should I be getting it some other way? 

thanks

mark

Code:

 

<P>protected void radgridSearchResults_SelectedIndexChanged(object sender, 
EventArgs e)<BR>        
{<BR>            //get 
the Selected Row and populate the 
Details...<BR>            
try<BR>            
{<BR>                
if (radgridSearchResults.SelectedValue != 
null)<BR>                
{<BR>                    
//GridDataItem dataItem = 
(GridDataItem)radgridSearchResults.SelectedItems[radgridSearchResults.SelectedItems.Count 
1];<BR>                    
//int selectedIndex = 
int.Parse(ViewState["CurrentRowIndex"].ToString());<BR>                    
//GridDataItem dataItem = 
(GridDataItem)radgridSearchResults.SelectedItems[selectedIndex];<BR>                    
//var scriptId = dataItem.GetDataKeyValue("id").ToString();</P>
<P>                    
var scriptId = radgridSearchResults.SelectedValue.ToString();</P>
<P>                    
                    
ViewState[Globals.CurrentScriptId] = scriptId;<BR>                    
//Pass Id to another function...
setDetails(
int.Parse(scriptId.ToString()));<BR>                    
}<BR>            
}<BR>            catch 
(System.Exception 
ex)<BR>            
{<BR>                
//Error code removed....
return
;<BR>            
}<BR>        }</P>

1 Answer, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 14 Jun 2011, 11:23 AM
Hi Mark,

SelectedIndexChanged is fired when selection is changed. In case when you have multiple rows selection enabled and you click on already selected row then selection is not changed because the row remains selected. You could handle grid's ItemCommand event then see if the command is RowClick and perform any custom action depending on your needs.

Aspx:
<telerik:RadGrid OnItemCommand="RadGrid1_ItemCommand" >
       ......
      <ClientSettings EnablePostBackOnRowClick="true">
        <Selecting AllowRowSelect="true" />
      </ClientSettings>
</telerik:RadGrid>

C#:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == "RowClick")
        {
               //do your logic here
        }
    }

I hope this helps.

Regards,
Vasil
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
mark baer
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Share this question
or