Witam tworzę sobie formularz sklepu i mam stworzony checkbox list w pliku *.aspx
wygląda on tak
<form id="form1" runat="server">
<asp:Label id="myLabel" runat="server">Test </asp:Label>
<img src="icones/cart.png" alt="Smiley face" height="3%" width="3%">
<center><asp:Label ID="Label1" runat="server" Font-Size="Large" ForeColor="Crimson">Wybierz kategorię pokemonów</asp:Label></center>
<asp:RadioButtonList ID="PokemonType" runat="server" AutoPostBack= "true">
<asp:ListItem Selected = "true">Wodny</asp:ListItem>
<asp:ListItem>Ognisty</asp:ListItem>
<asp:ListItem>Latający</asp:ListItem>
<asp:ListItem>Elektryczny</asp:ListItem>
</asp:RadioButtonList>
<br /><br />
<center><asp:Label ID="Label2" runat="server" Font-Size="Large" ForeColor="Crimson">Wybierz pokemona z listy</asp:Label></center>
<asp:CheckBoxList id="Pokemons" DataTextField= "name" RepeatDirection="Vertical" RepeatLayout="Flow" TextAlign="Right"
runat="server"/>
<br> <br> <br>
<asp:Button id="b1" Text="Dodaj zaznaczone" runat="server" />
</form>
oraz w code behind mam stworzone dodawanie do tej listy nowych obiektów i sprawdzanie które są zaznaczone, problem w tym że zawsze każdy jest niezaznaczony pomimo tego że go zaznaczyłem
protected void Page_Load(object sender, EventArgs e){
// check if page is post back (user clicked button)
for (int i = 0; i < Pokemons.Items.Count; i ++){ // sprawdzam które są zaznaczone
Console.Write(Pokemons.Items[i].Selected);
}
// adding new pokemons to list after changing the category
Pokemons.Items.Clear(); // czyszczę i dodaję na nowo bo user może zmienić grupę pokemonów
List<Product> temp = new List<Product>();
foreach (Product p in productList)
{
if (p.category.Equals(PokemonType.SelectedValue)){
temp.Add(p);
}
}
// binding value to set own class as list item in checkbox
Pokemons.DataSource = temp;
Pokemons.DataBind();
}
Nie wiem dlaczego tak się dzieje, nie może mi zczytywać wartości nowych gdyż najpierw mam sprawdzenie
Proszę się nie śmiać z tematu :P