views:

3377

answers:

3

I have a need to open a popup detail window from a gridview (VS 2005 / 2008). What I am trying to do is in the markup for my TemplateColumn have an asp:Button control, sort of like this:

<asp:Button ID="btnShowDetails" runat="server" CausesValidation="false"
   CommandName="Details" Text="Order Details" 
   onClientClick="window.open('PubsOrderDetails.aspx?OrderId=<%# Eval("order_id") %>',
   '','scrollbars=yes,resizable=yes, width=350, height=550');"

Of course, what isn't working is the appending of the <%# Eval...%> section to set the query string variable.

Any suggestions? Or is there a far better way of achieving the same result?

+2  A: 

I believe the way to do it is

onClientClick=<%# string.Format("window.open('PubsOrderDetails.aspx?OrderId={0}',scrollbars=yes,resizable=yes, width=350, height=550);", Eval("order_id")) %>
Tom Ritter
I like doing it in the markup to avoid cluttering the codebehind for such a small operation. I also avoid the use of FindControl whenever I can because it's not very quick.
Tom Ritter
I always have trouble with this approach inside of asp controls. But, if it works, go for it.
EndangeredMassa
+1  A: 

I like @AviewAnew's suggestion, though you can also just write that from the code-behind by wiring up and event to the grid views ItemDataBound event. You'd then use the FindControl method on the event args you get to grab a reference to your button, and set the onclick attribute to your window.open statement.

bdukes
+1  A: 

Do this in the code-behind. Just use an event handler for gridview_RowDataBound. (My example uses a gridview with the id of "gvBoxes".

Private Sub gvBoxes_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvBoxes.RowDataBound
    Select Case e.Row.RowType
        Case DataControlRowType.DataRow
            Dim btn As Button = e.Row.FindControl("btnShowDetails")
            btn.OnClientClick = "window.open('PubsOrderDetails.aspx?OrderId=" & DataItem.Eval("OrderId") & "','','scrollbars=yes,resizable=yes, width=350, height=550');"
    End Select 
End Sub
EndangeredMassa