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

Hide/Show Selected Row Cell Using JavaScript

6 Answers 151 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Venkata
Top achievements
Rank 1
Venkata asked on 05 Dec 2013, 09:17 PM
Hi,
I want show GridImage Cell when user Selected a Row and i want to Hide when user Un-Select the Row using JavaScript

 function grid_RowSelected(sender, args)
{
sender.get_masterTableView().showColumn(2);
}

But above method Shows or Hide the Column in Whole Radgrid. But I just want to Show/Hide User Select Row Cell/Column only

Thanks In Advance

6 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 06 Dec 2013, 05:30 AM
Hello,

Please check the below link. In this link i have already provided code snippet for same requirement.

http://www.telerik.com/community/forums/aspnet-ajax/grid/display-command-items-on-mouse-over.aspx

Note : In this demo i have used OnMouseOver/out you can use OnrowSelect/Deselect event.

Let me know if any concern.

Thanks,
Jayesh Goyani
0
Venkata
Top achievements
Rank 1
answered on 06 Dec 2013, 04:19 PM
Hi Jayesh Goyani,

Thank You for your quick Reply.. But it's not working.. here is my code
 
<telerik:GridImageColumn ImageUrl="~/images/Icons/time.png" UniqueName="timeImage" AllowFiltering="false">
</telerik:GridImageColumn>
 
<ClientSettings EnableRowHoverStyle="true">
 <ClientEvents OnRowSelected="grid_RowSelected" OnRowDeselecting="grid_RowDeselected" />            
</ClientSettings

And JavaScript.
function grid_RowSelected(sender, args)
{
 toggleContent(sender, args, true);
}
 
function toggleContent(sender, args, flag)
{
var wrapperEl = $telerik.getElementByClassName(args.get_gridDataItem().get_element(), "imgTime", "img");
if (wrapperEl)
    wrapperEl.style.visibility = flag ? "visible" : "";
}


I am getting wrapperEl as null
Am i missing any Thing..?
0
Eyup
Telerik team
answered on 11 Dec 2013, 11:59 AM
Hi Venkata,

I have created a sample RadGrid web site to demonstrate how you can achieve the requested functionality. Please run the attached application and let me know if it works for you.

Regards,
Eyup
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Venkata
Top achievements
Rank 1
answered on 12 Dec 2013, 07:02 PM
Hi Eyup,
Thanks and It worked.. One last question
I am storing the Select/Unselet value in my Session. Once user come back to Grid Screen how to show the Image if Previously selected?

here is my code and it's not working
protected void radGrid_PreRender(object sender, EventArgs e)
  {
     if (!IsPostBack)
     {
        if (HttpContext.Current.Session[MyObject] != null)
      {
        Image image = sender as Image;
        GridDataItem dataItem = image.NamingContainer as GridDataItem;
        image.Style["display"] = dataItem.Selected ? "" : "";
      }
     }
}

0
Eyup
Telerik team
answered on 17 Dec 2013, 11:55 AM
Hello Venkata,

You can achieve that by using the unique ID of the item:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (!IsPostBack && e.Item is GridDataItem)
    {
        GridDataItem dataItem = e.Item as GridDataItem;
        string itemID = Session["SelectedItemID"] as string;
 
        if (!string.IsNullOrEmpty(itemID))
        {
            string id = dataItem.GetDataKeyValue("OrderID").ToString();
            if (itemID == id)
            {
                dataItem.Selected = true;
            }
        }
    }
}

In addition, I'm attaching a sample to demonstrate how optimally you can navigate to and select the saved item from different page.

Looking forward to your reply.

Regards,
Eyup
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Venkata
Top achievements
Rank 1
answered on 17 Dec 2013, 03:45 PM
Hi Eyup

Thank You.. It Worked
Tags
Grid
Asked by
Venkata
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Venkata
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or