【问题标题】:Access selected record's grid value and passing to a new window using javascript访问选定记录的网格值并使用 javascript 传递到新窗口
【发布时间】:2012-08-09 06:26:05
【问题描述】:

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

【问题讨论】:

    标签: javascript .net gridview


    【解决方案1】:

    在新的 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')
                }
    

    【讨论】:

    • @yasir.:你建议使用锚标签。我必须在按钮字段中使用它。帮助我如何在按钮中使用它。!?
    • @AjithKumar 如果您希望它看起来像一个按钮,那么您可以使用“按钮”类型的输入标签而不是锚点,例如:&lt;input id="myButton" type="button" onClick="javascript:windowopen('&lt;%#Eval("ID") %&gt;')" /&gt;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-18
    • 1970-01-01
    相关资源
    最近更新 更多