我有一個問題,我搜索了很多,但沒有工作的答案 問題是:我創建動態GridView,然後添加動態創建的複選框到GridView和其添加但是當IAM試圖獲得複選框狀態(選中與否)我不能達到複選框 請幫助我,感謝這個馬麗娟網站獲取CheckBox在動態創建的GridView中動態創建
Dim MessagesTable As DataTable = Recipient.CreateInboxMessagesTable(LoginName, WhatToShow)
Dim Tbl As New DataTable
Dim Col As DataColumn
Dim Row As DataRow
Col = New DataColumn("ID", GetType(String)) : Tbl.Columns.Add(Col)
Col = New DataColumn("Select", GetType(String)) : Tbl.Columns.Add(Col)
Col = New DataColumn("Sender", GetType(String)) : Tbl.Columns.Add(Col)
Col = New DataColumn("Subject", GetType(String)) : Tbl.Columns.Add(Col)
Col = New DataColumn("ReceiveDate", GetType(String)) : Tbl.Columns.Add(Col)
Col = New DataColumn("Privacy", GetType(String)) : Tbl.Columns.Add(Col)
Col = New DataColumn("ImportanceLevel", GetType(String)) : Tbl.Columns.Add(Col)
Col = New DataColumn("JustDate", GetType(String)) : Tbl.Columns.Add(Col)
Col = New DataColumn("LastReplyID", GetType(String)) : Tbl.Columns.Add(Col)
Col = New DataColumn("Status", GetType(Integer)) : Tbl.Columns.Add(Col)
Col = New DataColumn("From", GetType(String)) : Tbl.Columns.Add(Col)
For Each TRow As DataRow In MessagesTable.Rows
Row = Tbl.NewRow
Row("ID") = TRow.Item("ID_Rec")
'Row("Select") = New CheckBox
Row("Sender") = Member.GetUserName(TRow.Item("From_Msg"))
Row("Subject") = TRow.Item("Subject_Msg") & " =+-+= " & Message.HTMLToText(TRow.Item("Body_Msg"))
Row("ReceiveDate") = Recipient.Convert24TimeTo12(TRow.Item("ReceiveDate_Rec")).Substring(11)
Row("Privacy") = TRow.Item("Privacy_Msg")
Row("ImportanceLevel") = TRow.Item("ImportanceLevel_Msg")
Row("JustDate") = TRow.Item("ReceiveDate_Rec")
Row("LastReplyID") = TRow.Item("LastReplyID_Msg")
Row("Status") = TRow.Item("Status_Msg")
Row("From") = TRow.Item("From_Msg")
Tbl.Rows.Add(Row)
Next
aGrid.DataSource = Tbl
aGrid.DataBind()
這就是我創建下面我怎麼添加的複選框我的網格視圖和代碼
For Each GVRow As GridViewRow In aGrid.Rows
Dim CB As New CheckBox
GVRow.Cells(1).Controls.Add(CB)
Next
這我如何試圖獲取複選框的狀態,但它並沒有工作
Protected Sub btnCompleted_Click(sender As Object, e As EventArgs) Handles btnCompleted.Click
For Each Row As GridViewRow In gvInbox.Rows
Dim cbSelect As CheckBox = DirectCast(Message.FindControlRecursive(Row, "CB"), CheckBox)
'If cbSelect.Checked = True Then
'End If
Next
End Sub
謝謝
您是否收到任何異常? – Sami
不,因爲我追蹤了代碼,並在它未能取回複選框 – Ali