I am having an issue with gridview and checkboxes in asp.net. I bind the grid at page load and add Attributes to the checkbox in the BindGrid() function:
chkSelection.Attributes.Add("onclick", "AbortPostBack(); __doPostBack('" + chkSelection.UniqueID + "','');")
AddHandler chkSelection.CheckedChanged, AddressOf ChkSelector_CheckedChanged
On page 1 I select some rows. I move to page 2, select another row. As soon as I do that, the entire grid just disappears!
On debugging, I found that grdSelect.Rows is 0 in the ReadGrid() function below:
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
Any suggestions/pointers would be really appreciated.