最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net - Including evalbind values in OnClientClick code - Stack Overflow

programmeradmin1浏览0评论

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?

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?

Share Improve this question edited Sep 19, 2008 at 14:42 Prestaul 85.1k10 gold badges88 silver badges85 bronze badges asked Sep 19, 2008 at 14:37 Ken RayKen Ray 2,5283 gold badges21 silver badges28 bronze badges 0
Add a comment  | 

3 Answers 3

Reset to default 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")) %>

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.

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
发布评论

评论列表(0)

  1. 暂无评论