我正在使用vb.net,我有一個gridview,其中包含四個列,包括Textbox作爲Itemtemplate字段。這個gridview包含了學生的信息,textbox是每個學生的出勤狀態。因此,要求將gridview中存在的所有文本框的輸入作爲每個學生出勤的輸入。在這裏,啓用尋呼功能是因爲有時候數字或學生可能超過80。但問題是,當我通過gridview行循環獲取文本框輸入時,它只是取第一頁的值,其餘的都保留下來。我真的需要幫助。任何幫助表示讚賞。如何在所有頁面中遍歷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
感謝。
嘗試 – rsmith
感謝每一頁循環後綁定你的GridView的回覆。我嘗試了你的建議,但仍然一樣。任何其他想法? – barsan