I'm working on a Webforms app, with CSS tabpages. Each tabpage contains a game. Due to the nature of the games, i have to force postbacks at various points in the app. Two of the apps have an asp:datagrid, both with a checkbox column and a text column. When i postback, the text list is retained, but the checkboxes all return to false. These checkboxes are purely for visual purposes. They have no real effect on the app, other than as a courtesy for the player to keep track of things. This is the markup...
This is how i bind it...Code:<asp:DataGrid ID="firstList" runat="server" CssClass="setlistbox" AutoGenerateColumns="false"> <Columns> <asp:TemplateColumn HeaderText="none1" ItemStyle-Width="20"> <ItemTemplate> <asp:CheckBox runat="server" ID="chkSelect" Checked='<%#Eval("Selecter").ToString() %>' /> </ItemTemplate> </asp:TemplateColumn> <asp:BoundColumn HeaderText="none2" DataField="TextItem"></asp:BoundColumn> </Columns> </asp:DataGrid>
I tried looping through the items server side...Code:dt1 = New DataTable dt1.Columns.Add("Selecter", GetType(Boolean)) dt1.Columns.Add("TextItem") dt1.Rows.Add(False, "example") firstList.DataSource = dt1 firstList.DataBind()
This prints out the correct values, but doesn't save the checkboxes' stateCode:For Each item As DataGridItem In firstList.Items Dim chkBox As CheckBox = DirectCast(item.FindControl("chkSelect"), CheckBox) Debug.Print(chkBox.Checked.ToString) dt1.Rows(item.ItemIndex).ItemArray(0) = chkBox.Checked ' this doesn't save the checkboxes' state Next
Can anyone help with this?




Reply With Quote