Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
379
Attach Client Side Onclick event from code-behind in UltraWebGrid
posted

I am using UltraWebGrid in my project. The requirement is that I need to attach a function for onclick event to only those cells which have a value in it and this can be done only from code-behind. But I'm unable to find a solution for this. I tried finding "Attributes.Add" for a cell from code-behind to attach a function on "onclick" event of the cell but there's no "Attributes" property for a cell.

Please suggest how can I attach the "onclick" event to only the desired cell through code-behind in a WebGrid.

Regards
Anuj

Parents
  • 45049
    posted

    Anuj,

    I assume that you're using a grid column whose Type is set to Button.

    You have two options here that I can see.

    One option is to use a templated column with buttons, rather than using a column with its Type set to Button.  You can then establish client-side event handlers to each button independently, or not establish them at all, as you choose.  This approach gives you the most control, at the cost of a significant amount of work to code and a likely decrease in performance (compared to not using a templated column).  If you're already using a templated column, then this is the approach I would recommend.

    The other option is to add logic to the ClickCellButton client-side event handler to selectively take action based on conditions with respect to the cell whose button was clicked.  For instance, you can choose to take action when another cell in the same row as the one whose button was clicked contains a value.  In this manner, the ClickCellButton event is still raised for all buttons, yet your logic still occurs only when it needs to occur.  If you're not using a templated column, then this is the approach I most recommend.

Reply Children