Select Row on GridButtonColumn click

6 posts, 1 answers
  1. Trey
    Trey avatar
    6 posts
    Member since:
    Sep 2012

    Posted 25 Nov 2013 Link to this post

    Perhaps this is by design, but it seems that if you set the client setting AllowRowSelect="true", the row is not selected when you click on a GridButtonColumn. For example, I have a GridButtonColumn for Delete, and if I select a row, it is selected, but then if I press the Delete button on a different row, the previous row is still selected. When I use ConfirmText, it could be confusing to the user since they might think they are about to delete the selected row instead of the row they clicked the delete button on.

    Is there an easy way to have the row selected that the GridButtonColumn was pressed in?
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 25 Nov 2013 Link to this post

    Hi Trey,

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

    ASPX:
    <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" Text="Delete"
      UniqueName="DeleteColumn"/>

    C#:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
     {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            ImageButton imgbtn = (ImageButton)item["DeleteColumn"].Controls[0];
            imgbtn.Attributes.Add("OnClick", "return Click('" + item.ItemIndex + "');");
        }
     }

    JS:
    <script type="text/javascript" language="javascript">
    function Click(RowIndex)
      {
        var RadGrid1 = $find("<%= RadGrid1.ClientID %>");
        RadGrid1.get_masterTableView().get_dataItems()[RowIndex].set_selected("true");
        var row = RadGrid1.get_masterTableView().get_dataItems()[RowIndex].get_element();
        var Name = row.cells[1].innerHTML;
        var agree = confirm('Do you want to delete the Product: ' + Name + '?');
        if (agree)
            {
             return true;
            }
        else
            {
             RadGrid1.get_masterTableView().get_dataItems()[RowIndex].set_selected("false");
             return false;
            }
      }
    </script>

    Thanks,
    Princy
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Oliver
    Oliver avatar
    1 posts
    Member since:
    Jan 2015

    Posted 17 Aug 2015 in reply to Princy Link to this post

    Hi Princy!

     I tried also this solution. Works fine for the 1st click. The 2nd click in another row doesn't work. I found out that if I click in the same row of the 1st click the row is deselected and then I can click in another row which is then selected.

    Do you have an idea what is wrong?

    Thank you,

    Oliver

  5. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 18 Aug 2015 Link to this post

    Hello Oliver,

    I have assembled a sample project using the suggested approach. The items are selected as expected on my end. I am attaching the project as reference. Please give it a try and see how it works for you.

    Regards,
    Viktor Tachev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Abitar
    Abitar avatar
    22 posts
    Member since:
    May 2015

    Posted 26 Aug 2015 Link to this post

    Hello,

    Can't I get the row index on GridButtonColumn click without firing an ItemDataBound or ItemCreated handlers ?

    I need to do this on client side using javascript only.

    I tried to do this using ItemDataBound event, It worked well for update commands but when I insert a new item to the RadGrid, and then click on the GridButtonColumn, I loose unsaved data in the RadGrid (Batch). 

    What can do to resolve this issue ?

    Thanks for the help !

    Abbas B.

     

  7. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 28 Aug 2015 Link to this post

    Hi Abbas,

    If you would like to add confirm message when Batch Editing you can use a GridClientDeleteColumn. It enables you to prompt the user before deleting a record.

    <telerik:GridClientDeleteColumn ConfirmText="Are you sure you would like to delete the record?"></telerik:GridClientDeleteColumn>


    Regards,
    Viktor Tachev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017