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

RadGrid Selected row highlight

3 Answers 357 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jay Mehta
Top achievements
Rank 1
Jay Mehta asked on 28 Jun 2010, 03:26 AM
Hi,

I have a radgrid with custom column having radio button, which allows only one selection at given time.
The functionality works perfect, but the problem I am facing is about the selected row color.

For eg: If I select first radio button, it highlights that row, now when I select another row, it de-selects the first selection but keeps it highlighted and also highlights the currently selected row.

Please let me know, exactly what I can do to avoid this situation.

Thank you,
Jay Mehta.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 28 Jun 2010, 10:33 AM
Hi,

I have tried similar approach of using RadioButton in RadGrid for allowing single selection by adopting the approach described in the code library. I got it worked as expected and not able to find any issue as you described.
Code Library : Single RadioButton check at a time with row selection


Try the approach suggested in code library and see whether it help. In case this does not help you, please paste the code that you tried?


Princy.
0
Jay Mehta
Top achievements
Rank 1
answered on 28 Jun 2010, 03:54 PM
Thanks Princy for the response. But this not exactly what I am facing. The single radiobutton  check at one time is working fine, but the issue I am facing is the highlighted effect of the row. Once the row is de-selected it should remove the highlight, but it is not.
below is my code:
<telerik:RadGrid ID="dgCompanyData"  Width="650px" AllowMultiRowSelection="true" 
        runat="server" AllowSorting="True" GridLines="None" AutoGenerateColumns="true" > 
<selecteditemstyle  CssClass="SelectedItem"></selecteditemstyle> 
  <MasterTableView  PageSize="10"
                    <Columns> 
                       <telerik:GridTemplateColumn HeaderText="Active Account" UniqueName="RadioTemplateColumn"
                            <ItemTemplate> 
                                <asp:RadioButton ID="RadioButton3" OnCheckedChanged="ComapnyData_ToggleRowSelection" AutoPostBack="True" runat="server"/>  
                            </ItemTemplate> 
                        </telerik:GridTemplateColumn> 
                    </Columns> 
                </MasterTableView> 
        <ClientSettings EnableRowHoverStyle="true"
         </ClientSettings> 
    </telerik:RadGrid> 
<script language="javascript" type="text/javascript"
 
function SelectMeOnly(objRadioButton, grdName)  
     { 
       
    var i, obj;  
    for (i=0; i<document.all.length; i++)  
     {  
      obj = document.all(i);  
      
      if (obj.type == "radio")  
       {  
         
      if (objRadioButton.id.substr(0, grdName.length) == grdName)  
      if (objRadioButton.id == obj.id)  
             obj.checked = true;  
      else { 
             obj.checked = false
             obj.selected = false; } 
       }  
    }      
    }   
</script> 
   Protected Sub ComapnyData_ToggleRowSelection(ByVal sender As Object, ByVal e As EventArgs) 
         
        CType(CType(sender, RadioButton).Parent.Parent, GridItem).Selected = CType(sender, RadioButton).Checked 
 
    End Sub 
 
 
 
    Protected Sub dgCompanyData_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles dgCompanyData.ItemDataBound 
        If TypeOf e.Item Is GridDataItem Then 
            Dim item As GridDataItem = DirectCast(e.Item, GridDataItem) 
            Dim radbtn As RadioButton = DirectCast(item("RadioTemplateColumn").FindControl("RadioButton3"), RadioButton) 
            radbtn.Attributes.Add("OnClick", "SelectMeOnly(" + radbtn.ClientID + ", " + "'dgCompanyData'" + ") ") 
        End If 
    End Sub 

Thank you,
Jay Mehta
0
Princy
Top achievements
Rank 2
answered on 29 Jun 2010, 05:43 AM
Hello Jay,

From your code, I can see that you set AllowMultiRowSelection property to "True" which allows multiple rows to be selected at the same time. Probably setting this property to false will eliminates your problem.

Thanks,
Princy.



Tags
General Discussions
Asked by
Jay Mehta
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jay Mehta
Top achievements
Rank 1
Share this question
or