radgrid rows not selected on textbox click

5 posts, 0 answers
  1. Allen
    Allen avatar
    49 posts
    Member since:
    Oct 2012

    Posted 25 Oct 2012 Link to this post

    Hi
         I have a radgrid in which iam using template columns. I am selecting radgrid rows on clicking a row. But when i click on the textbox in templatecolumn, the row is not getting selected.Please help me out.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 25 Oct 2012 Link to this post

    Hi,

    Please try the following code snippet to select a row on TextBox click.

    ASPX:
    <telerik:GridTemplateColumn UniqueName="TempCol" HeaderText="TempCol" >
        <ItemTemplate>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        </ItemTemplate>
    </telerik:GridTemplateColumn>

    C#:
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = (GridDataItem)e.Item;
                int index = item.ItemIndex;
                TextBox txtbx = (TextBox)item["TempCol"].FindControl("TextBox1");
                txtbx.Attributes.Add("OnClick", "return Select('" + index + "');");
            }
    }


    Javascript:
    <script type="text/ecmascript">
    function Select(index)
    {
        var grid = $find("<%= RadGrid1.ClientID %>");
        grid.MasterTableView.get_dataItems()[index].set_selected(true);   
    }
    </script>

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 26 Oct 2012 Link to this post

    Hello,

    By mistake Princy forget to add C# code.

    So please try with updated code.

    <telerik:GridTemplateColumn>
        <ItemTemplate>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        </ItemTemplate>
    </telerik:GridTemplateColumn>


      protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
             
            if (e.Item is GridDataItem)
            {
                TextBox TextBox1 = e.Item.FindControl("TextBox1") as TextBox;
                TextBox1.Attributes.Add("onclick", "Select('"+e.Item.ItemIndex+"');");
            }
    }
    function Select(index) {
                   var grid = $find("<%= RadGrid1.ClientID %>");
                   grid.MasterTableView.get_dataItems()[index].set_selected(true);
               }


    Thanks,
    Jayesh Goyani
  5. Ankush
    Ankush avatar
    4 posts
    Member since:
    Dec 2013

    Posted 06 Dec 2014 Link to this post

    Hi Jayesh/Princy/All,

    I am facing an issue. Row is getting highlighted when I click on the text in the row but when I click on the empty space in the row, row is not getting highlighted. 

    It seems no event is firing on clicking on empty space in the row(screenshot attached). Please help !

    Thanks,
    Ankush
  6. Eyup
    Admin
    Eyup avatar
    3012 posts

    Posted 11 Dec 2014 Link to this post

    Hi Ankush,

    Can you please elaborate on your specific configuration? The rows should be selected as expected on cell click:
    http://demos.telerik.com/aspnet-ajax/grid/examples/functionality/selecting/row-selection/defaultcs.aspx

    Regards,
    Eyup
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017