Including eval / bind values ​​in OnClientClick code

I need to open a popup with gridview (VS 2005/2008). What I'm trying to do is markup for my TemplateColumn, has an asp: Button control, kind of like:

<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 doesn't work is adding the section <% # Eval ...%> to set the query string variable.

Any suggestions? Or is there a much better way to achieve the same result?

+7
javascript visual-studio
source share
3 answers

I believe the way to do this is

 onClientClick=<%# string.Format("window.open('PubsOrderDetails.aspx?OrderId={0}',scrollbars=yes,resizable=yes, width=350, height=550);", Eval("order_id")) %> 
+13
source share

I like @ AviewAnew , although you can also just write this from code-code by posting and event to the grid. Event ItemDataBound. Then you used the FindControl method for the event arguments that you received to get a link to your button, and set the onclick attribute to your window.open statement.

+2
source share

Do it in code. Just use an event handler for gridview_RowDataBound. (My example uses gridview with id "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 
+2
source share

All Articles