访问所选记录的网格值并使用javascript传递到新窗口

时间:2012-08-09 06:26:06

标签: javascript .net gridview

在我的表单中,当我单击网格视图中的编辑按钮时,我需要打开一个新窗口。另外必须将相应的ID值传递给新窗口。我在新窗口中编写了打开的代码但是它没有用。我搜索并无法找到如何将所选记录的ID值发送到新窗口。帮助我如何做到这一点。

     <asp:GridView ID="gridUserDetails" runat="server" BackColor="White" 
                                BorderColor="#336666" BorderStyle="Double" BorderWidth="3px" CellPadding="4" 
                                GridLines="Horizontal" AutoGenerateColumns="False" AllowSorting="true"  
                                onselectedindexchanged="gridUserDetails_SelectedIndexChanged" onsorting="SortingGridData">
                                <Columns>                                     
                           <asp:BoundField DataField="ID"  HeaderText="ID" SortExpression="ID" />
                           <asp:BoundField DataField="Name"  HeaderText="Employee Name" SortExpression="Name" />
                           <asp:BoundField DataField="Address" HeaderText="Employee Address" SortExpression="Address" />
                           <asp:BoundField DataField="Email"  HeaderText="Employee Mail"  SortExpression="Email"/>
                           <asp:BoundField DataField="Department"  HeaderText="Department"  SortExpression="Department"/>
                    <asp:TemplateField>
                    <ItemTemplate>
                    <asp:Button ID="btnEdit" CausesValidation="false" runat="server" Text="Edit" 
                    onClientClick="windowopen()"/>


                    </ItemTemplate>
                    </asp:TemplateField>

                                </Columns>
                                <FooterStyle BackColor="White" ForeColor="#333333" />
                                <HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
                                <PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
                                <RowStyle BackColor="White" ForeColor="#333333" />
                                <SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
                                <SortedAscendingCellStyle BackColor="#F7F7F7" />
                                <SortedAscendingHeaderStyle BackColor="#487575" />
                                <SortedDescendingCellStyle BackColor="#E5E5E5" />
                                <SortedDescendingHeaderStyle BackColor="#275353" />

                            </asp:GridView>       

这是我的Grid的代码。下面是我的javascript

     <script language="javascript" type="text/javascript">
 function windowopen() {
           mywindow = window.open('ISSRegistrationForm.aspx', 'Employee Details', 'height=500, width=1100, status=no, resizable=no, scrollbars=yes, toolbar=no,location=no, menubar=no'
            }
            </script>

1 个答案:

答案 0 :(得分:0)

在新的TemplateField的ItemTemplate中创建一个锚(标记):

<asp:TemplateField><ItemTemplate><a href="onclick="javascript:windowopen('<%#Eval("ID") %>')">Click Here</a></ItemTemplate></asp:TemplateField>

并且您的JavaScript函数应如下所示:

    function windowopen(id) {
mywindow = window.open('ISSRegistrationForm.aspx?id='+id, 'Employee Details', 'height=500, width=1100, status=no, resizable=no, scrollbars=yes, toolbar=no,location=no, menubar=no')
            }