我正在使用 vb.net,并且我有一个 gridview,其中包含四列,包括 Textbox 作为 Itemtemplate 字段。该网格视图包含学生的信息,文本框是学生每天的出勤状态。因此,要求是将网格视图中存在的所有文本框的输入作为每个学生的学生出勤的输入。在这里,启用分页是因为人数或学生有时可能超过 80 人。但问题是,当我遍历 gridview 行以获取文本框输入时,它只获取第一页的值,其余的都留下了。我真的需要这方面的帮助。任何帮助表示赞赏。
这是 GridView 代码:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" BorderColor="Black" BorderStyle="Solid"
CellPadding="4" Font-Bold="True" Font-Size="Small" ForeColor="#333333"
OnPageIndexChanging="GridView1_PageIndexChanging" PageSize="20">
<Columns>
<asp:TemplateField HeaderText="No.">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="crkod" HeaderText="Student ID" />
<asp:BoundField DataField="crnama" HeaderText="Student Name" />
<asp:TemplateField HeaderText="Attendance Status"
ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:TextBox ID="txtAttend" runat="server" BackColor="Control" MaxLength="1"
Width="12px"></asp:TextBox>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle Font-Bold="True" />
</asp:GridView>
这是保存按钮背后的代码:
For k As Integer = 0 To Me.GridView1.PageCount - 1
Me.GridView1.PageIndex = k
Dim rowNum As Integer = Me.GridView1.Rows.Count
For i As Integer = 0 To rowNum - 1
Dim tb As TextBox = DirectCast(GridView1.Rows(i).FindControl("txtAttend"), TextBox)
attendSts = tb.Text
studntID = GridView1.Rows(i).Cells(1).Text
Sql = "INSERT INTO attendance (studentID,attendStatus,attendDate,courseID,yearsem,monthsem)" _
& " VALUES (" _
& "'" & studntID & "'," _
& "'" & attendSts & "'," _
& "'" & attnDate & "'," _
& "'" & courseCode & "'," _
& yearsem & "," _
& monthsem & ")"
CreateCommand(Sql, strConn)
Next
Next
提前致谢。