1

I have a webgrid, which is stated below

@grid.GetHtml(tableStyle: "webgrid", 
              headerStyle: "webgrid-header", 
              footerStyle: "webgrid-footer", 
              alternatingRowStyle: "webgrid-alternating-row", 
              selectedRowStyle: "webgrid-selected-row", 
              rowStyle: "webgrid-row-style"
             )

Since my columns are dynamic i am not defining any columns in the webgrid.

My question is, How do I link a particular column to open a popup?

Please let me know.

1 Answer 1

0

Add a class to the item (an achor tag? ) where you want to show a popup when clicking on that. So your HTML may be rendered as something like

<a href="user/details/12" class="aPopup">View details</a>

Now have a little bit of jQuery code to listen to the click event of the link and show a popup. You may simply call the window.open method which opens a page in a new window or use plugin to show a model popup.

$(function(){
  $("a.aPopup").click(function(e){
     e.preventDefault();

     var popupUrl=$(this).attr("href");

     //code to show popup here
     //window.open or model popup plugin call

  });    
});

There are a number of plugins there to show a model popup. check out jQuery UI dialog.

5
  • Hi Shyju, when i gave href its not rendering the same as html instead it shows <a href="user/details/12" class="aPopup">View Extra details</a>. How can i make this look like HTML with hyperlink. I am doing this from my sql query.
    – Vijay Pote
    Commented May 29, 2013 at 18:39
  • what you mean by html with hyperlink ? Is that a tag not enough for you ?
    – Shyju
    Commented May 29, 2013 at 18:41
  • so my sql has SELECT DISTINCT r.ReportName AS [Report Name] ,r.ReportDesc AS [Report Desc] ,'<a href="user/details/12" class="aPopup">View Extra details</a>' AS [Report Extra Details] FROM r.Reports now when i run this on web grid i was expecting the display as Voew Extra Details with out the <a href and all. Why on the webgrid it shows as <a href="user/details/12" class="aPopup">View Extra details</a> ?
    – Vijay Pote
    Commented May 29, 2013 at 18:47
  • Hi Shyju, basically i want to render the column data "<a href="user/details/12" class="aPopup">View Extra details</a>" as html on the grid, rest your jquery should work for me.
    – Vijay Pote
    Commented May 29, 2013 at 19:38
  • I solved the issue foreach (KeyValuePair<string, object> keyValuePair in eachFlowRow) { if (keyValuePair.Key.Contains("Report Extra Details")) { var newEntry = new KeyValuePair<string, object>(keyValuePair.Key, @Html.Raw("<a href='Home/Index' class='aPopup'>Vijay</a>")); row.Add(newEntry); } else { row.Add(keyValuePair); } }
    – Vijay Pote
    Commented May 30, 2013 at 3:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.