我需要帮助将网格视图中选定行的变量传递到弹出窗口。我需要创建一个循环,它将遍历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
答案 0 :(得分:1)
这些应该引导你朝着正确的方向前进:
Display GridView Row Details using ASP.NET AJAX Popup Control
Html popup window from code behind file
基本上,您发送的行数据会在动态弹出窗口中显示。就个人而言,我认为AJAX方法(第一个链接)更干净,但我不知道你是否在使用Microsoft AJAX库。