Row select using check box checked in Rad grid

4 posts, 0 answers
  1. Trs
    Trs avatar
    11 posts
    Member since:
    Jan 2013

    Posted 25 Jan 2013 Link to this post

    I'm using telerik radgrid view.I have grid view with check boxes.Check boxes are insert to the grid using edit item template. I want to select current row when i'm checking check box.I try to find a solution.but still didn't found solution to my problem. Any inputs will be appreciated and welcome.Thanks
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 25 Jan 2013 Link to this post

    Hi,

    Try the following code.
    C#:
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
           CheckBox chk = (CheckBox)sender;
           GridEditFormItem editItem=(GridEditFormItem)chk.NamingContainer;
           GridDataItem ditem = (GridDataItem)editItem.ParentItem;
           ditem.Selected = true;
    }

    Thanks,
    Shinu
  3. Trs
    Trs avatar
    11 posts
    Member since:
    Jan 2013

    Posted 25 Jan 2013 Link to this post

    Thank you very much shinu. But i want to do this using javascript.(Client side.).Do you have any solutions?
  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 28 Jan 2013 Link to this post

    Hi,

    One suggestion is to add a javascript 'OnClick' event in the ItemCreated event on the RadGrid and pass the row index to select the particular row. Please take a look into the following code snippet I tried.

    C#:
    protected void Radgrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditFormItem && (e.Item.IsInEditMode))
        {
            GridEditFormItem eitem = (GridEditFormItem)e.Item;
            GridDataItem ditem = (GridDataItem)eitem.ParentItem;
            int index = ditem.ItemIndex;
            CheckBox chk = (CheckBox)eitem.FindControl("CheckBox1");
            chk.AutoPostBack = true;
            chk.Attributes.Add("OnClick", "SelectRow('"+index+"')");
        }
    }

    Javascript:
    <script type="text/javascript">
        function SelectRow(index) {
            var grid = $find("<%=Radgrid1.ClientID%>");
            var MasterTable = grid.get_masterTableView();
            var row = MasterTable.get_dataItems()[index];
            row.set_selected(true);
        }
    </script>

    Thanks,
    Shinu.
Back to Top