7

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?

0

3 Answers 3

13

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")) %>
Sign up to request clarification or add additional context in comments.

3 Comments

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.
I always have trouble with this approach inside of asp controls. But, if it works, go for it.
A word of warning - question asks about Eval and Bind, but this approach will only work for Eval. Bind is handled differently internally, and won't allow such constructs
2

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.

Comments

2

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

Comments

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.