0

我需要帮助将变量从网格视图中的选定行传递到弹出窗口。我需要创建一个循环,该循环将通过 gridview 并为选定的每一行,并将行详细信息传递给弹出模板中的对应标签,并为选定的每个附加行设置一个分页符。谁能指出我正确的方向,或者有人可以帮助我编写代码吗?

这是我当前的html代码:

<title> </title>

<script>

    function SelectAllCheckboxes(spanChk) {

        // Added as ASPX uses SPAN for checkbox
        var oItem = spanChk.children;
        var theBox = (spanChk.type == "checkbox") ?
            spanChk : spanChk.children.item[0];
        xState = theBox.checked;
        elm = theBox.form.elements;

        for (i = 0; i < elm.length; i++)
            if (elm[i].type == "checkbox" &&
                     elm[i].id != theBox.id) {
                //elm[i].click();
                if (elm[i].checked != xState)
                    elm[i].click();
                //elm[i].checked=xState;
            }
    }
</script>


</head>
<body>
<form id="form1" runat="server">
<div>

    <asp:LoginStatus ID="LoginStatus1" runat="server" />
    <br />
    <br />

    <br />
    <asp:Button ID="print2" runat="server" Text="Print" />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />

    <br />
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CertificateID" DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display.">
        <Columns>

            <asp:TemplateField ShowHeader="true">
                <HeaderTemplate>
                    <input id="chkAll" onclick="javascript: SelectAllCheckboxes(this);" runat="server" type="checkbox"/>                       
                </HeaderTemplate>
                <ItemTemplate>                      
                   <asp:CheckBox ID="chkSelect" runat="server" />
                </ItemTemplate>                    
            </asp:TemplateField>
            <asp:BoundField DataField="CertificateID" HeaderText="CertificateID" InsertVisible="False" ReadOnly="True" SortExpression="CertificateID" />
            <asp:BoundField DataField="Customs_Entry" HeaderText="Customs_Entry" SortExpression="Customs_Entry" />             
            <asp:BoundField DataField="Date_Certificate" HeaderText="Date_Certificate" SortExpression="Date_Certificate" />
            <asp:BoundField DataField="Invoice_Number" HeaderText="Invoice_Number" SortExpression="Invoice_Number" />
            <asp:BoundField DataField="Product_Number" HeaderText="Product_Number" SortExpression="Product_Number" />
            <asp:BoundField DataField="Product_Name" HeaderText="Product_Name" SortExpression="Product_Name" />
            <asp:BoundField DataField="Product_Category" HeaderText="Product_Category" SortExpression="Product_Category" />
            <asp:BoundField DataField="CPSC_Regulation" HeaderText="CPSC_Regulation" SortExpression="CPSC_Regulation" />
            <asp:BoundField DataField="Date_Manufactured" HeaderText="Date_Manufactured" SortExpression="Date_Manufactured" />
            <asp:BoundField DataField="Manufacturer" HeaderText="Manufacturer" SortExpression="Manufacturer" />
            <asp:BoundField DataField="Date_Tested" HeaderText="Date_Tested" SortExpression="Date_Tested" />
            <asp:BoundField DataField="Test_Lot_ID" HeaderText="Test_Lot_ID" SortExpression="Test_Lot_ID" />
            <asp:BoundField DataField="Name_Laboratory" HeaderText="Name_Laboratory" SortExpression="Name_Laboratory" />
        </Columns>

    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:LocalSqlServer %>" DeleteCommand="DELETE FROM [Certificate] WHERE [CertificateID] = @CertificateID" InsertCommand="INSERT INTO [Certificate] ([Customs_Entry], [Date_Certificate], [Invoice_Number], [Product_Number], [Product_Name], [Product_Category], [CPSC_Regulation], [Date_Manufactured], [Manufacturer], [Date_Tested], [Test_Lot_ID], [Name_Laboratory]) VALUES (@Customs_Entry, @Date_Certificate, @Invoice_Number, @Product_Number, @Product_Name, @Product_Category, @CPSC_Regulation, @Date_Manufactured, @Manufacturer, @Date_Tested, @Test_Lot_ID, @Name_Laboratory)" ProviderName="<%$ ConnectionStrings:LocalSqlServer.ProviderName %>" SelectCommand="SELECT [CertificateID], [Customs_Entry], [Date_Certificate], [Invoice_Number], [Product_Number], [Product_Name], [Product_Category], [CPSC_Regulation], [Date_Manufactured], [Manufacturer], [Date_Tested], [Test_Lot_ID], [Name_Laboratory] FROM [Certificate]" UpdateCommand="UPDATE [Certificate] SET [Customs_Entry] = @Customs_Entry, [Date_Certificate] = @Date_Certificate, [Invoice_Number] = @Invoice_Number, [Product_Number] = @Product_Number, [Product_Name] = @Product_Name, [Product_Category] = @Product_Category, [CPSC_Regulation] = @CPSC_Regulation, [Date_Manufactured] = @Date_Manufactured, [Manufacturer] = @Manufacturer, [Date_Tested] = @Date_Tested, [Test_Lot_ID] = @Test_Lot_ID, [Name_Laboratory] = @Name_Laboratory WHERE [CertificateID] = @CertificateID">
        <DeleteParameters>
            <asp:Parameter Name="CertificateID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="Customs_Entry" Type="String" />
            <asp:Parameter Name="Date_Certificate" Type="String" />
            <asp:Parameter Name="Invoice_Number" Type="String" />
            <asp:Parameter Name="Product_Number" Type="String" />
            <asp:Parameter Name="Product_Name" Type="String" />
            <asp:Parameter Name="Product_Category" Type="String" />
            <asp:Parameter Name="CPSC_Regulation" Type="String" />
            <asp:Parameter Name="Date_Manufactured" Type="String" />
            <asp:Parameter Name="Manufacturer" Type="String" />
            <asp:Parameter Name="Date_Tested" Type="String" />
            <asp:Parameter Name="Test_Lot_ID" Type="String" />
            <asp:Parameter Name="Name_Laboratory" Type="String" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="Customs_Entry" Type="String" />
            <asp:Parameter Name="Date_Certificate" Type="String" />
            <asp:Parameter Name="Invoice_Number" Type="String" />
            <asp:Parameter Name="Product_Number" Type="String" />
            <asp:Parameter Name="Product_Name" Type="String" />
            <asp:Parameter Name="Product_Category" Type="String" />
            <asp:Parameter Name="CPSC_Regulation" Type="String" />
            <asp:Parameter Name="Date_Manufactured" Type="String" />
            <asp:Parameter Name="Manufacturer" Type="String" />
            <asp:Parameter Name="Date_Tested" Type="String" />
            <asp:Parameter Name="Test_Lot_ID" Type="String" />
            <asp:Parameter Name="Name_Laboratory" Type="String" />
            <asp:Parameter Name="CertificateID" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <br />
    <br />
    <br />
    <br />

</div>
</form>

这是我的VB:

Imports System.Text

Public Class WebForm4
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub


Protected Sub GridView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles GridView1.SelectedIndexChanged
    'Check All Checkboxes Code:
    ' StringBuilder object
    Dim str As New StringBuilder()

    ' Select the checkboxes from the GridView control
    For i As Integer = 0 To GridView1.Rows.Count - 1
        Dim row As GridViewRow = GridView1.Rows(i)
        Dim isChecked As Boolean = DirectCast(row.FindControl("chkSelect"), CheckBox).Checked

        If isChecked Then
            ' Column 2 is the name column
            str.Append(GridView1.Rows(i).Cells(2).Text)
        End If
    Next

    ' prints out the result
    Response.Write(str.ToString())


End Sub
End Class
4

1 回答 1

1

这些应该会引导您朝着正确的方向前进:

使用 ASP.NET AJAX 弹出控件显示 GridView 行详细信息

来自文件后面代码的 Html 弹出窗口

基本上,您正在发送要在弹出窗口中即时显示的行数据。就个人而言,我认为 AJAX 方法(第一个链接)更干净,但我不知道您是否使用 Microsoft AJAX 库。

于 2012-10-09T22:30:44.610 回答