loop through datagrid...postback?

liunx

Guest
Hello.

On my code behind .aspx.vb page I have the following code for a button:


Private Sub btnRetreive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRetreive.Click
Dim checkedCnt As Integer = 0
Dim dgItem As DataGridItem
Dim chkSelected As CheckBox
For Each dgItem In dg.Items
chkSelected = dgItem.FindControl("chkThisOne")
If chkSelected.Checked Then
checkedCnt += 1
End If
Next
End Sub



Here is the checkbox I have on my .aspx page:

<asp:TemplateColumn>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:CheckBox ID="chkThisOne" Runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>



It is not finding anything that is checked, even though I have things checked. Is this due to postback? Any ideas?

Thanks for your time!OK, so I figured something out. If I do this in my page load, it works but my sorting stops working:


If Not Page.IsPostBack Then
BindData()
End If


But if I do this, my sorting works but looping through my datagrid doesn't. Any ideas on what to do?

If Not Page.IsPostBack Then

End If
BindData()


Thanks!
 
Back
Top