GridView中的复选框问题
本文关键字:问题 复选框 GridView | 更新日期: 2023-09-27 18:25:44
我在asp.net中遇到了网格视图和复选框的问题。我在页面加载时绑定网格,并在BindGrid()函数中向复选框添加属性:
chkSelection.Attributes.Add("onclick", "AbortPostBack(); __doPostBack('" + chkSelection.UniqueID + "','');")
AddHandler chkSelection.CheckedChanged, AddressOf ChkSelector_CheckedChanged
在第1页上,我选择了一些行。我移到第2页,选择另一行。我一这么做,整个网格就消失了!
在调试时,我发现在下面的ReadGrid()函数中,grdSelect.Rows为0:
in Page_Load
If Not Page.IsPostBack Then
BuildData()
BindGrid()
RenumberPager()
Dim ctlControl As UserControl = PageUtility.SearchControl(Page.Master, "ctlLeadsCount")
CType(ctlControl, leadscount).Count = m_SelectedRecords.Count
Else
ReadGrid()
End If
in ReadGrid
For Each row As GridViewRow In grdSelect.Rows
Dim chkSelection As CheckBox = CType(row.FindControl("ChkSelector"), CheckBox)
If Not chkSelection Is Nothing Then
Dim recNumK As DataKey = CType(grdSelect.DataKeys(row.RowIndex), DataKey)
Dim recNum As String = recNumK.Value.ToString()
m_SelectedRecords.Remove(recNum)
If chkSelection.Checked = True Then
For Each rec As Record In m_data
If rec(BusinessFieldNames.UniqueId) = recNum Then
m_SelectedRecords(recNum) = rec(BusinessFieldNames.UniqueId)
Exit For
End If
Next
End If
End If
Next
ViewState("Cherry") = m_SelectedRecords
任何建议/建议都将不胜感激。
您必须在gridView_PageIndexChanging事件中重新绑定数据。此外,在绑定之前,您必须设置网格视图的页面索引属性,如下所示:
Protected Sub grdSelect_PageIndexChanging(...) Handles grdSelect.PageIndexChanging
grdSelect.PageIndex = e.NewPageIndex
BuildData()
BindGrid()
end sub
希望能有所帮助。