RadGrid does not highlight row until selected twice

2 posts, 0 answers
  1. Judy
    Judy avatar
    1 posts
    Member since:
    Oct 2016

    Posted 07 Oct Link to this post

    I have a radGrid with EnablePostBackOnRowClick="True".

    it includes an OnSelectedIndexChanged event: OnSelectedIndexChanged="grdSpecialtyMedTasks_OnSelectedIndexChanged"

    It includes a column :<telerik:GridClientSelectColumn UniqueName="ClientSelectColumn" ItemStyle-Width="20px"/>

    My codebehind includes :

    protected void grdSpecialtyMedTasks_OnSelectedIndexChanged(object sender, EventArgs e)
    {                                                       // when I click a row, I hit this code every time
    GridDataItem selectedItem = (GridDataItem)grdSpecialtyMedTasks.SelectedItems[0];
    DropDownList ddlDest = (DropDownList)selectedItem.FindControl("ddlDest");
    if (ddlDest.SelectedValue != "Default")
        {
        btnProcessTask.Enabled = true;
        }
    ...

    protected void btnProcessTask_Click(object sender, EventArgs e)
    {
    if (grdSpecialtyMedTasks.SelectedItems[0] != null) // occasional index out of range error hits here
         {       
        processTask(sender, e);
         }
    }

    ---------------------------

    When user selects anywhere in the row, the client select checkbox is checked and vices-versa, so that seems to work nicely.

    Also when either of the above happens I can see that the OnSelectedIndexChanged fires as I hit a breakpoint each time. (double click hits breakpoint twice.)

    Problem is that the row does not APPEAR to have been selected / does not get highlighted until the user double-clicks the row. WHY?

    In case it matters, both times when I hit breakpoint in the OnSelectedIndexChanged method, IsPostBack is set to True.

    The potential is that the user thinks they are processing Row X when in fact they are processing Row Y.

    Also, occasionally I am getting am index out of range error in the btnProcessTask_Click method.

    --------------------------

    Any assistance greatly appreciated :)

     

     

  2. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 12 Oct Link to this post

    Hi Judy,

    Note that the ClientSelectColumn is intended to be used for client-side selection. If you would like to have server-side selection in the Grid I would recommend to use the approach described in the following article.


    Moreover, for disabling the button you can use client-side logic. Please examine the following code-snippets that illustrate the approach. Give it a try and let me know how it works for you.

    <telerik:GridTemplateColumn UniqueName="TemplateColumn">
        <ItemTemplate>
            <asp:Button ID="Button1" Text="Click" runat="server" />
        </ItemTemplate>
    </telerik:GridTemplateColumn>


    <ClientSettings EnablePostBackOnRowClick="true">
        <ClientEvents  OnRowCreated="rowCreated" />
        <Selecting AllowRowSelect="true" />
    </ClientSettings>


    function rowCreated(sender, args) {
        var grid = sender;
        var dataItem = args.get_gridDataItem();
        var templateColumn = dataItem.get_cell("TemplateColumn");
        var button = $telerik.findElement(templateColumn, "Button1");
     
        if (!dataItem.get_selected()) {
            button.disabled = "disabled";
        }
         
    }



    Regards,
    Viktor Tachev
    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top