这是我的aspx页面:
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
Station Reading = CreateStation("Reading", "Great Western", true);
Station Bristol = CreateStation("Bristol", "Great Western", false);
Station York = CreateStation("York", "Great Eastern", true);
System.out.println("What Station do you need to know about? ");
String UsrStation = s.nextLine();
System.out.println(staGetName(York)+" "+staGetOp(York)+" "+staGetStep(York));
}
public static Station CreateStation(String StationName, String Operator, Boolean StepFree){
Station s = new Station();
staSetName(s, StationName);
staSetOp(s, Operator);
staSetStep(s, StepFree);
return s;
}
//Getter Methods for Station
public static String staGetName(Station s){
return s.name;
}
public static String staGetOp(Station s){
return s.operator;
}
public static Boolean staGetStep(Station s){
return s.stepFree;
}
//Setter Methods for Station
public static Station staSetName(Station s, String name){
s.name = name;
return s;
}
public static Station staSetOp(Station s, String operator){
s.operator = operator;
return s;
}
public static Station staSetStep(Station s, Boolean stepFree){
s.stepFree = stepFree;
return s;
}
}
class Station{
String name;
String operator;
Boolean stepFree;
}
这是我的vb类:
<asp:ListView ID="ListViewHRDFormIzin" runat="server" DataSourceID="SqlDataStaffHRDFormIzin" DataKeyNames="STAFF_NIK" EnableViewState="false">
<LayoutTemplate>
<table id="dataTable" class="table table-bordered striped data" align="left">
<thead style="background-color: #4877CF">
<!-- add checkbox -->
<th style="text-align: center; color: white">Check</th>
<th style="text-align: center; color: white">NIK</th>
</thead>
<asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<asp:CheckBox ID="CheckBox1" runat="server" />
</td>
<td style="text-align: center">
<asp:Label ID="lbl" runat="server" Text='<%# Eval("STAFF_NIK")%>'></asp:Label></td>
<td style="text-align: center">
<asp:LinkButton ID="lnkSelect" Text='DETAIL' CommandName="Select" runat="server"><img src="img/detail.png" width="50px" height="50px" /></asp:LinkButton></td>
</tr>
</ItemTemplate>
<EmptyDataTemplate>Data Izin Karyawan Tidak diketemukan</EmptyDataTemplate>
<EmptyItemTemplate>Data Izin Karyawan Tidak diketemukan</EmptyItemTemplate>
</asp:ListView>
<asp:Button ID="Button1" Visible="true" runat="server"
Text="Get Data" class="btn btn-success" />
我也已将此代码添加到页面加载中:
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'get data from chekced checkbox
Dim ChkValue As New List(Of String)()
For Each item As ListViewItem In ListViewHRDFormIzin.Items
Dim ck As CheckBox = DirectCast(item.FindControl("CheckBox1"), CheckBox)
If ck.Checked Then
ChkValue.Add(DirectCast(item.FindControl("lbl"), Label).Text)
End If
Next
For Each itms As String In ChkValue
Response.Write("<script>alert('Value Selected: " + itms + "')</script>")
Next
Response.Write("<script>window.location.href='HRDFORMIZIN.aspx';</script>")
End Sub
我还想念什么?当我按下button1时,它什么也不做。我的意思是,没有价值得到。只需转到:
If IsPostBack = False Then
ListViewHRDFormIzin.DataBind()
End If
我正在尝试通过从ID ='lbl'的标签中检索值来检查每行的值。但是button1总是一无所有
答案 0 :(得分:0)
由于设置了EnableViewState="false"
,列表视图在回发时丢失了数据。尝试将其设置为true
。