0

在我的表单中,当我单击网格视图中的编辑按钮时,我需要打开一个新窗口。还必须将相应的 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>
4

1 回答 1

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')
            }
于 2012-08-09T06:38:01.933 回答