« ExecuteNonQuery Always Returns -1 | Main | Maintaining Collection Property State for Web Custom Controls »

October 05, 2006

More Control Over GridView Column

My blog has moved. Please go to: http://jstawski.com/archive/2006/10/05/More-Control-Over-GridView-Column.aspx

In response to the many comments/questions regarding the post on GridView, HyperLinkField, and JavaScript: what the #%[email protected]! I decided to extend it and show how you can have total control over a column with the GridView.

Whenever you need to do something that is not out of the box with the GridView, like adding RadioButtons, Adding JavaScript, etc you can use the <asp:TemplateField> In there you have total control as far as what you want to insert on that column. Following the issue with the JavaScript from my other post there is an example on how to do achieve the same results:
<asp:TemplateField>
  <ItemTemplate>
    <%#"<a href=""javascript:MM_openBrWindow('../images/elevations/" & Eval("Column1") & "','img" & Eval("Column2") & "','');"">" & Eval("Column1") & "</a>"%>
  </ItemTemplate>
</asp:TemplateField>

02:19 PM | Permalink

Comments

After a couple of hours searching for a solution, this finally did the trick! I really got stuck with passing two variables into a javascript function, but your solution worked (although I replaced the double double quotation marks with one single quotation mark)! Thanx!

Posted by: Tom | Oct 13, 2006 7:58:18 AM

Thank You Very MUCH!!!

Posted by: Connie | Oct 17, 2006 6:18:06 PM

Thanks for tip Jonas. That solved two problems I was having with the hyperlinkfield but created a new one: now when I sort the gridview by clicking on a column header, my templatefield column is blank (no data) although it still appears to sort. Any ideas to get around this?

Posted by: Ben Lorincz | Nov 15, 2006 12:27:37 PM

Good tip Jonas. How could you code this so that if the record doesn't have a corresponding image, you don't make the bound item clickable. I.e. I have a data set where there can be anywhere from 0 to 3 images available for a record. If there are 0 I don't want that "0" to be clickable, whereas if there are more than 0 (1 to 3), I do want it clickable to a new window to display them.

Posted by: Mundo | Mar 1, 2007 4:26:39 AM

Thank you! I used this to create a javascript popup link inside a GridView... it's unfortunate that you can't do this out of the box!

Posted by: Brett Coburn | Sep 1, 2009 10:04:42 AM

How to make script run without postback?

Posted by: kuan | Oct 19, 2009 6:36:53 AM

The comments to this entry are closed.