Pages

Friday, November 11, 2011

Java Pop-up window from GridView Row Selection


Hi, the following is a complete sample.  I would assume rsSearch is a function defined as <script>  rsSearch(var id) {     }   </script>  
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
                    AutoGenerateColumns="False" DataKeyNames="CategoryID" DataSourceID="ObjectDataSourceCategory"
                    CellPadding="4" ForeColor="#333333" GridLines="None" Font-Size="8pt" Font-Names="Verdana"
                    Width="100%" EmptyDataText="There are no categories defined" PageSize="10">
                    <Columns>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:LinkButton ID="btnDetails" runat="server" Text="Details" CausesValidation="false" />
                                <asp:LinkButton ID="btnDelete" runat="server" Text="Delete" CausesValidation="false"
                                    CommandName="Delete" />
                                <asp:Panel ID="pnlPopup" CssClass="catdetpopup" Width="450px" runat="server" Style="display: none;"
                                    Visible="true">
                                    <div style="width: 100%; height: auto; background-repeat: repeat-x; color: Black;
                                        font-family: Calibri" id="dragdiv" runat="server">
                                        <div style="float: right">
                                            <asp:Image runat="server" ID="btnClose" ImageUrl="/globalimages/close_button.gif" />
                                        </div>
                                        <div style="padding: 10px">
                                          <uc1:ucCategoryDetails ID="CategoryDetails1" Cat_id='<%# Eval("CategoryID")%>' runat="server">
                                            </uc1:ucCategoryDetails>
                                        </div>
                                    </div>
                                </asp:Panel>
                                <cc1:ModalPopupExtender ID="mdlpopup1" runat="server" TargetControlID="btnDetails"
                                    PopupControlID="pnlPopup" BackgroundCssClass="popupbackground" DropShadow="true"
                                    Drag="true" PopupDragHandleControlID="dragdiv" CancelControlID="btnClose" />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField DataField="CategoryID" HeaderText="CategoryID" InsertVisible="False"
                            Visible="False" ReadOnly="True" SortExpression="CategoryID" />
                        <asp:BoundField DataField="CategoryName" HeaderText="Category Name" SortExpression="CategoryName" />
                        <asp:CheckBoxField DataField="IsActive" HeaderText="Active" SortExpression="IsActive" />
                    </Columns>
                  
                </asp:GridView>
Css
.catdetpopup
{
    width:500px;
    height:auto;
    border:1px solid black;
    background-color:White;
}
UserControl codebehind
Partial Public Class ucCategoryDetails
    Inherits System.Web.UI.UserControl
    Private _Cat_ID As String
    Public Property Cat_id() As String
        Get
            Return _Cat_ID
        End Get
        Set(ByVal value As String)
            _Cat_ID = value
            Me.odsSubCat.SelectParameters("Cat_ID").DefaultValue = CInt(Cat_id)
          
        End Set
    End Property
End Class
Hope this Helps

------------------------
<script type="text/javascript">
<!-- Begin
function popUp(URL) {day = new Date();
id = day.getTime();
eval(
"page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300,left = 390,top = 362');");
}
// End -->
</script>
Followed by the gridview template.
<ItemTemplate>
<asp:HyperLink ID="idTracking" runat="server" Style="position: relative" Text='<%# Eval("ItemID") %>'NavigateUrl="popUp('../ItemDetail/Default.aspx?ItemID=')"></asp:HyperLink>
</ItemTemplate>
Followed by the VB code behind.
Protected Sub GridView2_RowDataBound(ByVal sender As ObjectByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)Handles GridView2.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim hl As HyperLink = DirectCast(e.Row.FindControl("idTracking"), HyperLink) hl.NavigateUrl = "javascript:" + hl.NavigateUrl
End If
End Sub

No comments:

Post a Comment